xiphirx wrote:lotios611 wrote:I think it should be
Code: Select all
#include "mapeditor.h"
class mapEditor;
Both ways are not working
No. Look, you should have a header with the class prototype, where you define the object as being part of your class. So for this, you don't need to know what the object does. You don't need to know its functions, members or usage. So you simply forward declare, such as
foo.h
Code: Select all
#ifndef SOMETHING
#define SOMETHING
class Bar;
class Foo {
Bar* var;
Foo();
};
#endif
Then when you want to use the object in your source file, you are free to INCLUDE the entire object's prototype, so that you can use the functions and members.
foo.cpp
Code: Select all
#include "foo.h"
#include "bar.h"
Foo::Foo(){
var = new Bar();
var->DoSomething();
var->someMember = RANDOM_THING;
}
SO a recap. IN MOST CASES: In the header, you FORWARD DECLARE. In the source file, you INCLUDE.
edit:
That's about as good as I can explain it. I found this example code for you to look through if you're still having problems.
Example code for forward declaration
The trick is to think about what the compiler knows. If you say class Something; the compiler knows you have a class called Something, so you can hold pointers to it but you can't use it's functions because the compiler doesn't know about them.