View Single Post
Old 06-01-2005, 04:39 AM   #3
twisted-mystic
Abandonia nerd

 
Join Date: Dec 2004
Location: ,
Posts: 60
Default

More polymorphism
here is an Eg:

class object
{
public:
char* name;
};

class box : public object
{
public:
int width;
}
class forklift : public object

class whouse
{
void putObjectInWhouse(object)
object whatsInMyWHouse();
}


ok so the whouse object can return two things, a forklift or a box, since i want to be able to put either or both in whouse, i accept an argument of object, so i have to put out a object , object.

the problim is, when i call whatsInMyWhouse() and say i have something that can tell if it's a forklift or box, how does that function treat it like it's proper object, that is box or forklift, like this

int main()
{
whouse myWHouse;
box myBox;
myWHouse.putObjectInWhouse(myBox);
cout << myWHouse.whatsInMyWHouse().width;
}

if i do that, (given that it's coded with proper syntax), i get a compiler exception saying width is not a member of object, but it is of Box, and i know the object it's handing me is a box.... my question is, how do i treat it as a box, and not just an object..

I'm having a hard time explaining this too, so if i can claify please let me know.

And Thanks!!
twisted-mystic is offline                         Send a private message to twisted-mystic
Reply With Quote