As the title says. I have this exact problem with my bigger project, but I decided to check for the same issue on this little test model. It turns out the issue is still present and I've tried everything I could find out there but it's still the same. I've tried the article
The IDE I used is Code::Blocks which manages all compiling and linking (I made sure that the files were added in the project and set for both compiling and linking) and the compiler is gcc.
This is the exact error I get:
main.cpp|9| undefined reference to `Calc::add2(int, int)'
And these are all the files:
main.cpp:
#include <iostream>
#include "add.h"
using namespace std;
int main()
{
Calc a;
cout<<"2 + 2 = "<<a.add(2,2);
return 0;
}
add.h:
#ifndef ADD_H_INCLUDED
#define ADD_H_INCLUDED
struct Calc
{
int add(int a, int b);
};
#endif // ADD_H_INCLUDED
add.cpp:
struct Calc
{
int add(int a, int b)
{
return a + b;
}
};