Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 03-21-2007, 09:02 AM   #1 (permalink)
True Techie
 
Join Date: Dec 2004
Posts: 131
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   Reply With Quote
Old 03-21-2007, 04:22 PM   #2 (permalink)
True Techie
 
void's Avatar
 
Join Date: Oct 2005
Posts: 199
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   Reply With Quote
Old 04-13-2007, 09:17 PM   #3 (permalink)
Ultra Techie
 
Join Date: Apr 2005
Posts: 897
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   Reply With Quote
Reply

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



All times are GMT -5. The time now is 11:10 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0