A big THANK YOU for using code tags! You are one of the few newbies that actually read the rules and follow them from the first post.
2 things that caught my eye right away:
Never include cpp files. Since they are implementation files, all that should be required is that you add them to your project's workspace.
Secondly, you need to place you class definitions in header files (.h). These header files are then included by your .cpp files that use the functions, or in the case of the class method implementation cpp files, define the functions.
In case that wasn't clear, here's what I mean:
// myclass.h
#ifndef MYCLASS_H // note: these are very important!
#define MYCLASS_H
class myClass {
public:
void myFunc();
// blah blah blah
};
#endif
// myclass.cpp
#include "myclass.h"
void myFunc::myClass() {
// etc
}
// main.cpp
#include "myclass.h"
int main() {
myClass myObj;
}
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
Thanks! Your suggestion solved the errors! My only question is, why do i need the #ifndefine, #define, #endif etc. ?
It's to prevent multiple inclusions. Let's take that previous example that we had before, but now you need to include this class in other files as well:
// otherclass.cpp
#include "myclass.h"
// blah blah blah
// anotherclass.cpp
#include "myclass.h"
// blah blah blah
Now, normally the header code would be pasted into the cpp files by the compiler's preprocessor. But this would cause errors because you are redefining the class. You are only allowed to define a class once. Using #ifndef/#define/#endif checks to see if it has already been included by another file. If so, it does nothing, and no errors happen.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
>I see, so the commands that start with "#" are messages to the compiler.
Yup. The technical name for them is "preprocessor directives", so don't freak out if you hear that term. :)
>Thanks alot!
Glad I could help.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339