B
Bint
Hello,
I am wondering if someone can answer this for me. I have a base class,
with function Copy(). It is supposed to make a copy of the class. I define
it as virtual.
Then I have a subclass of that, and I give it it's own Copy() function. How
do I make sure that the subclass' Copy() function is called, and not the
base class?
For example:
class Thread { public:
unsigned char type;
virtual Thread *Copy();
};
class geothreadublic Thread { public:
virtual Thread *Copy();
};
Thread *newt, *t = object->thread; // can be either base or subclass
Newt = t->Copy();
My program is always calling the base class' Copy(), when I want it to call
whichever one is appropriate depending on whether object->thread is really a
base or a sub. Is there anyway for it to know?
Thanks
B
I am wondering if someone can answer this for me. I have a base class,
with function Copy(). It is supposed to make a copy of the class. I define
it as virtual.
Then I have a subclass of that, and I give it it's own Copy() function. How
do I make sure that the subclass' Copy() function is called, and not the
base class?
For example:
class Thread { public:
unsigned char type;
virtual Thread *Copy();
};
class geothreadublic Thread { public:
virtual Thread *Copy();
};
Thread *newt, *t = object->thread; // can be either base or subclass
Newt = t->Copy();
My program is always calling the base class' Copy(), when I want it to call
whichever one is appropriate depending on whether object->thread is really a
base or a sub. Is there anyway for it to know?
Thanks
B