problem with my C++ class'

Status
Not open for further replies.

weewun

In Runtime
Messages
160
hey.

im currently making a program in C++ and have a bit of trouble with the class'.
in a header file, i am declareing 2 classes, playerData, and item. in the playerData class, there is a function that requires an 'item' object. when i try to compile, it says that 'item was not declared in this scope'.

i am curious as to the code to insert to let the compiler know that there is an 'item' class comming later, similar to letting the compiler know that there is a function comming. cheers for any help.
 
You need to include the class item. This is done by #include "item.h" in playerData.h

item.h
Code:
class item {
public:
     void method1();
};

playerData.h
Code:
#include "item.h"

class playerData {
public:
     void method2(item i);
};
 
Remember, to access something else, you need to include that file. Where else is it going to get the member functions/data from???
 
Status
Not open for further replies.
Back
Top Bottom