I'm having some trouble figuring out how to assign values to member data when calling a virtual function through a heterogeneous list.
Here's an example of what I'm trying to do:
class A
{
protected:
virtual void func1();
private:
A * list;
}
class B: public A
{
protected:
void func1();
private:
int i1, i2;
}
Within main():
list = new A[10];
list[0] = new B;
list[0]->Func1();
Declaration of Func1():
void B::Func1()
{
int a, b;
cin >> a >> b;
list[0]->i1 = a;
list[0]->i2 = b;
// or can I just do this:
// i1 = a;
// i2 = b;
}
I'm looking for the appropriate way to access member data of a derived class within a function of the derived class if calling via a pointer of the parent class from main. Any help would be much appreciated!