Hello (or good evening perhaps), Being a beginner in C++, I decided for the first time to split my code into several parts. So I created a main.cpp file, a carre.hpp file and a carre.cpp file with the following codes :
main.cpp
#include <iostream>
#include <string>
#include "carre.hpp"
using namespace std;
void direBonjour(){
cout << "Bienvenue dans le Metteur au Carre !!!" << endl;
}
int main(){
direBonjour();
double a(0.), b(0.);
cout << "Entrer le nombre que vous voulez mettre au carre :" << endl;
cin >> a;
b = con(a);
cout << "Nombre Originale : " << a << ". Nombre au Carre : " << b << "." << endl;
}
carre.cpp
#include "carre.hpp"
double con(double x){
double result(x*x);
return result;
}
carre.hpp
#ifndef CARRE_HPP
#define CARRE_HPP
double con(double x);
#endif // CARRE_HPP
When I run my program in the terminal I get this error:
undefined reference to `con(double)'collect2.exe: error: ld returned 1 exit status
I use Visual Studio Code and I use MinGW, the C/C++ extension integrated to VS Code as well as Code Runner to run my programs. I created these files one by one by putting them in the same folder. I think it's a compilation problem but I haven't found solutions to my problem.
I hope you can help me.
Thank you in advance.
Axel Hippolite.