'Undefined reference to in C++
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<<")";
}
Solution 1:[1]
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
Solution 2:[2]
Finally, I found the solution: The mistake I did is I didn't create a C++ project in visual studio code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | long.kl |
| Solution 2 | mustapha |
