error: 'biblio::Reference::Reference' names the constructor, not the type

Hi, I made a class that contain a pur virtual method wich I will implement it in the derivatives classes. But for now, I got an error in my .cpp file...here the essential part of my code :

---Reference.h------

#ifndef REFERENCE_H_
#define REFERENCE_H_
#include "ContratException.h"
#include "validationFormat.h"
#include <sstream>

namespace biblio
{
class Reference
{
public:
Reference(const std::string& p_auteurs, const std::string&
p_titre, int p_annee, const std::string& p_identifiant); // constructeur
virtual ~Reference(){};

//Acesseurs (Getters)
const std::string& reqAuteurs() const;
const std::string& reqTitre() const;
int reqAnnee() const;
const std::string& reqIdentifiant() const;

//Mutateur (Setter)
void asgAuteurs(const std::string& p_nouveauxAuteurs);


virtual std::string reqReferenceFormate() const;
virtual bool operator==(const Reference& deuxiemeReference)
const;
virtual Reference* clone() const; //HERE IS THE PUR VIRTUAL METHOD THAT I'M TALKING ABOUT

private:
void verifieInvariant() const;
std::string m_auteurs;
std::string m_titre;
int m_annee;
std::string m_identifiant;
};

} /* namespace biblio */

#endif /* REFERENCE_H_ */


----Reference.cpp--------

#include "Reference.h"

namespace biblio
{
Reference::Reference(const std::string& p_auteurs, const std::string&
p_titre, int p_annee, const std::string& p_identifiant):
m_auteurs(p_auteurs), m_titre(p_titre), m_annee(p_annee), m_identifiant(p_identifiant)
{}
/**
* Some codes defines the functions in the class Reference
*/

//Pur virtual method
Reference::Reference* clone() const //error: ‘biblio::Reference::Reference’
//names the constructor, not the type
{
return 0;
}

/**
* Some codes
*/
} /* namespace biblio */
---------------------------------------
I'm french guy, sorry if my english have hurt your eyes...
And I must «implement» Reference* clone() const in .cpp, otherwise I got an error in others files (my test files) wich says :
the type must inherited pure virtual method "biblio::Reference::Reference* clone()"

I have search on internet for example wich I could resolve the error but none...

Last edited on
Your clone() function is not pure virtual. For this you need to add = 0.

virtual Reference* clone() const = 0; // Note: = 0

If you don't add '= 0' you need to implement the function, otherwise you will get a linker error.

Do not add the scope operator:
Reference::Reference* clone() const //error: ‘biblio::Reference::Reference’

Instead I suggest to use the keyword override:
Reference* clone() const override;
I have find out...all I have do is a Reference* Reference::clone() const !
Topic archived. No new replies allowed.