Hello, I know the code is correct but for some reason when I compile the code it says "[Linker error] undefined reference to 'myFun::add(int,int)'" . I am compiling in Dev c++. Here is my code:
Functions.h
1 2 3 4 5 6 7 8 9 10 11
#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <iostream>
usingnamespace std;
class myFun
{
public:
int add(int x, int y);
};
#endif
Functions.cpp
1 2 3 4 5 6 7 8
#include <iostream>
usingnamespace std;
#include "Functions.h"
int myFun::add(int x, int y)
{
return x+y;
}
text.cpp
1 2 3 4 5 6 7 8 9 10
#include <iostream>
usingnamespace std;
#include "Functions.h"
int main()
{
int pause;
myFun ignite;
cout<<ignite.add(2,4);
cin>>pause;
}
Also I did notice in the file the header file "Functions.h" is saved as a C Header File where the rest of the files are C++ Source File. How do I change Functions.h to a C++ Header File and do I have to change it?
Is "Functions.cpp" linked in your project? Check "Project -> Remove From Project" at the top of the IDE's window. If you do not see it listed the you need to add it with "Project -> Add to Project" which should be right above the other command.
Oh yeah, stop using Dev-C++, it's old and bad and stuff.
EDIT: Another way to do this is to go to: "Window -> List" this will pop-up with the files linked in your project.