how to use lists with abstract class
```c++
#include
#include<iostream>
using namespace std;
class BC{
public:
void show_class(){
show1();
show2();
}
private:
void show1(){
cout << "#1 BC\n";
}
virtual void show2(){
cout << "#2 BC\n";
}
};
class DC : public BC{
private:
void show1(){
cout << "#1 DC\n";
}
virtual void show2(){
cout << "#2 DC\n";
}
};
class DDC : public DC{
private:
void show1(){
cout << "#1 DDC\n";
}
virtual void show2(){
cout << "#2 DDC\n";
}
};
int main()
{
BC b;
b.show_class(); // #1 BC, #2 BC
cout << endl;
DC d;
d.show_class(); // #1 BC , #2 DC
cout << endl;
DDC dd;
dd.show_class(); // #1 BC , #2 DDC
cout << endl; // show_class is in BC class, so it shows its show1() function because of no virtuality
return 0;
}
#include <iostream>
using namespace std;
class One{
public:
int F(){return 2;}
virtual int G(){return 3;}
};
class Two: public One{
public:
int F(){return 4;}
int G(){return 5;}
};
class Three: public Two{
public:
int G(){return 7;}
};
int main()
{
One * p1;
One ob1;
Two ob2;
Three ob3;
p1 = &ob1; // base
cout << p1->F() * p1->G(); // = 6
cout << endl;
p1 = &ob2;
cout << p1->F() * p1->G(); // int F() is not virtual therefore
cout << endl; // it take the base function =2*5 =10
p1 = &ob3;
cout << p1->F() * p1->G(); // 2*7 = 14
cout << endl;
Two * p2;
p2 = &ob3;
cout << p2->F() * p2->G(); // 4 * 7 = 28 the f() function from Two
cout << endl; // there is virtual G function...
return 0;
}
```c++
#include