You need to put macro guards in the .h files with the class declarations. Class functions are placed in the .cpp file. Your .cpp file should have #include "foo.h".
Your .h file
Code:
#ifndef FOO_H
#define FOO_H
class foo
{
private:
int num1, num2, num3;
public:
....
....
int calcNum (int, int);
};
#endif
Your .cpp file
Code:
#include "foo.h"
int foo::calcNum (int a, int b)
{
num3 = num1 + num2;
return num3;
}
Code:
#include "foo.h"
int main ()
{
foo x;
.....
.....
x.calcNum ();
return 0;
}
NB: This does not apply to template classes. With templates, both the declaration and their operations must be within the .h file.
Hope that helps.
Sophie