Bonnjour a tous,
J'ai un probleme de surcharge d'opérateurs et je ne sais pas comment le régler. La compilation se passe bien ('g++ -c *.cpp -Wall -pedantic') mais quand je veux lancer le fichier (avec 'g++ -o Project main.o'), le terminal m'affiche l'erreur suivante:
voici mes opérateurs dans le .cpp:main.o: In function `main':
main.cpp.text+0x131): undefined reference to `Point::operator==(Point const&) const'
main.cpp.text+0x147): undefined reference to `Point::operator!=(Point const&) const'
main.cpp.text+0x193): undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, Point const&)'
dans le .hpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 bool Point::operator==(const Point& p) const{//operateur== return (p.getX()==this->getX()) and (p.getY() == this->getY());} bool Point::operator!=(const Point& p) const{//operateur!= return not((p.getX()==this->getX()) and (p.getY() == this->getY()));} void Point::afficher(ostream& out) const{ out << "(" << x << ", " << y << " )"; } ostream &operator<<(ostream &out, const Point &p){//operateur de sortie p.afficher(out); return out; }
Je ne sais vraiment pas comment regler ce probleme!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 private: bool operator==(const Point& p) const;//operateur == bool operator!=(const Point& p) const; ... public: std::ostream &operator<<(std::ostream &out, const Point &p);
Merci d'avance de votre aide!![]()
Partager