0

Please, can someone help me to solve this error.

the error I get is "undefined reference to" all functions, constructors and destructor that I implemented.

main.cpp

#include <iostream>
#include "vecteur.hpp"
using namespace std;

int main(){
    Vecteur vect1(2,1,3),vect2(3,6,4);
    vect1.affiche();
}

vecteur.hpp

class Vecteur{
    public:
    Vecteur();
    Vecteur(float abscisse, float ordonnee, float hauteur);
    ~Vecteur();
    void affiche();

    private:
    float m_abscisse;
    float m_ordonnee;
    float m_hauteur;
};

vecteur.cpp

#include <iostream>
#include "vecteur.hpp"
using namespace std;


Vecteur::Vecteur():m_abscisse(0),m_ordonnee(0),m_hauteur(0)
{

}
Vecteur::Vecteur(float abscisse, float ordonnee, float hauteur):m_abscisse(abscisse),m_ordonnee(ordonnee),m_hauteur(0)
{

}
Vecteur::~Vecteur(){
    cout<<"L'adresse du vecteur détruit est : "<<this;
}
void Vecteur::affiche()
{
    cout <<"("<<m_abscisse<<","<<m_ordonnee<<","<<m_hauteur<<")";
}

image of the error

mustapha
  • 1
  • 1
  • You should add `vecteur.cpp` to the arguments of the compiler. Something like `g++ main.cpp vecteur.cpp`. – clemens Mar 12 '22 at 09:17
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – BoP Mar 12 '22 at 09:26

2 Answers2

0

your IDE miss vecteur.cpp durring compiling, I think you need to write a CmakeLists.txt or Makefile to specify how your program will be compiled ( flags, libraries,..).

to test quickly your program use this command

g++ main.cpp vecteur.cpp -o output && ./output
long.kl
  • 670
  • 4
  • 12
0

Finally, I found the solution: The mistake I did is I didn't create a C++ project in visual studio code.

mustapha
  • 1
  • 1