M
Mike Frayn
Hi there. I'm wondering how to achieve a particular
functionality using virtual functions and class
inheritance... I don't know if its possible, but I figured
that I would give it a shot.
What I want is to have a base class with particular member
data and a virtual function that will be overloaded by the
inheriting class.
class CBaseClass
{
public:
virtual void OverLoadMe(void) {}
int DataFieldA;
};
In the inherited class, I will overload the function but I
would like to introduce new member data:
class CInheritedClassA : public CBaseClass
{
void OverLoadMe(void) { //happy now? }
float DataFieldB;
};
Now if I defined a variable like so:
CBaseClass* MyClass = new CInheritedClassA;
I would like to be able to access DataFieldB. Of course, I
can't, however the reason I'm looking for such functionality
is so that I can house a group of inheritedclassA-Z
instances in one list without having to have separate lists
for separate types.
So, while I do realize that this doesn't work, and
furthermore I also realize WHY this doesn't and shouldn't
work, I'm wondering if I can get around it without
COMPLETELY changing the design of what I have so far.
Thanks so much,
Mike
functionality using virtual functions and class
inheritance... I don't know if its possible, but I figured
that I would give it a shot.
What I want is to have a base class with particular member
data and a virtual function that will be overloaded by the
inheriting class.
class CBaseClass
{
public:
virtual void OverLoadMe(void) {}
int DataFieldA;
};
In the inherited class, I will overload the function but I
would like to introduce new member data:
class CInheritedClassA : public CBaseClass
{
void OverLoadMe(void) { //happy now? }
float DataFieldB;
};
Now if I defined a variable like so:
CBaseClass* MyClass = new CInheritedClassA;
I would like to be able to access DataFieldB. Of course, I
can't, however the reason I'm looking for such functionality
is so that I can house a group of inheritedclassA-Z
instances in one list without having to have separate lists
for separate types.
So, while I do realize that this doesn't work, and
furthermore I also realize WHY this doesn't and shouldn't
work, I'm wondering if I can get around it without
COMPLETELY changing the design of what I have so far.
Thanks so much,
Mike