Can I not reference another class within a class?
I'm having some trouble with classes...again. I just can't seem to get my head around them.
I made a class for the player, and classes for the weapons, armor, items, etc that he will use, but everytime I reference the instance of the class for the particular item, It says that I haven't defined it. I make sure that I have all the necessary instances defined in the same function, but it still didn't work. Here is some sample code:
Code:
#include <iostream>
using namespace std;
class item {
public:
item () {}
~item () {}
void use ( void ) {
cout << "This item is pretty cool";
}
};
class person {
public:
person(){}
~person(){}
void useone ( void ) {
cout << "Hello World\n";
item1.use(); //ERROR: 'item1' undeclared (first use this function)
}
};
int main()
{
item item1;
person bob;
bob.useone();
cout << "Did it fail?";
cin.get();
}