0

Hi,

I have a question related to pointers to base and derived classes. I have the following base and derived class:

class A
{
protected:
double a,x;
public:
void set_ax();
virtual void mult_ax();
};

class B:virtual public A
{
protected:
double b;
public:
void set_b();
void mult_ax();
};

class C:virtual public A
{
protected:
public:
};

class D
{
protected:
double d;
public:
void set_d();
};

class E:public B, public C, public D
{
protected:
public:
};

I am trying to access the base class objects and dervived class objects using pointers. By declaring a base class pointer to class A i am able to point to objects created from B and C. However I am not sure how to access the objects created from E which has two different base class. How would I go about doing this. Any help is appreciated.

Thank you

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by nalasimbha
0

Delcare two pointers; class D and class A to have an address of object of class E,

int main(){
   A *a;
   D *d;

   E e;
   a=&e;
   d=&e;

   a->mult_ax();
   d->set_d();
   return 0;
}

Take a look at tutorial - Polymorphism

Edited by __avd: n/a

0

Thank you for the suggestion. However this way the person should know which function belongs to which base class :) . Another question I would like to ask is:
If the derived class E has its own function say set_e(), which point would i need to downcast? Can I downcast either *a or *d?

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.