I have Class A as a base class , and Class B , C derived classes from A and there's class D who have a data member (pointer to Array) of type A (Composition)
enter code here
class D{
A **a;
int size;
.......
a = new A*[size];
......
};
and i have Print method , in its body i have to specific element (if it from class B or C ) with a given ID(both B and C have a data member ID ) there should be 2 options in print function .. printing elements for class B , or printing elements for class C ? how can i specific the elements ?
i made class A abstract!!
enter code here
class A{
.......
virtual void print ()=0;
};
class B :public A{
........
........
void print(){
.......}
};
class C :public A{ ........ ........ void print(){ .......} };
class D{
........
.......
void Print ()
int P;
cout<<" if you want to print class B elements enter 1 , or 2 for class C"<<endl;
cin>>P;
if(P==1){
dynamic_cast<B*>(*a)->print(); }
else
if (P== 2){
dynamic_cast<C*>(*a)->print(); }
my Question here is how can i specific the elements if it from class B or C ???