Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » problem with my C++ class'
Closed Thread
Old 03-21-2007, 10:02 AM   #1 (permalink)
 
True Techie

Join Date: Dec 2004

Posts: 138

weewun is on a distinguished road

Default problem with my C++ class'

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.
weewun is offline  
Old 03-21-2007, 05:22 PM   #2 (permalink)
void's Avatar
 
True Techie

Join Date: Oct 2005

Posts: 198

void

Default Re: problem with my C++ class'

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);
};

void is offline  
Old 04-13-2007, 10:17 PM   #3 (permalink)
 
Ultra Techie

Join Date: Apr 2005

Posts: 950

M4A1 is on a distinguished road

Send a message via AIM to M4A1
Default Re: problem with my C++ class'

Remember, to access something else, you need to include that file. Where else is it going to get the member functions/data from???
M4A1 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On