W
Wolfgang
Hi,
I'm trying to understand how could I inherit a nested class. Say for
instance - I've four classes namely class A, class B, class C, class
D.
[ 1 ] class B is nested inside class A
[ 2 ] class D is nested inside class C
[ 3 ] I'm trying to inherit class D from class B.
[ 4 ] Instantiating 'class A::B' as 'abObj' and want to understand
which all constructors get called.
But the code seems to throw compilation error and any help is
appreciated. Pasting below sample code:
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<"A::A"<<endl;
}
class B{
public:
B(){
cout<<"B::B"<<endl;
}
~B(){
cout<<"B::~B"<<endl;
}
};
~A(){
cout<<"A::~A"<<endl;
}
};
class C{
public:
C(){
cout<<"C::C"<<endl;
}
class D{
public:
D(){
cout<<"D:"<<endl;
}
~D(){
cout<<"D::~D"<<endl;
}
};
~C(){
cout<<"C::~C"<<endl;
}
};
class A::B : public C:{
public:
A::B() {
cout<<"A::B::A::B"<<endl;
}
~A::B(){
cout<<"A::B:~A::B"<<endl;
}
};
int main(){
A::B abObj;
return 0;
}
Pls guide !
- Wg
I'm trying to understand how could I inherit a nested class. Say for
instance - I've four classes namely class A, class B, class C, class
D.
[ 1 ] class B is nested inside class A
[ 2 ] class D is nested inside class C
[ 3 ] I'm trying to inherit class D from class B.
[ 4 ] Instantiating 'class A::B' as 'abObj' and want to understand
which all constructors get called.
But the code seems to throw compilation error and any help is
appreciated. Pasting below sample code:
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<"A::A"<<endl;
}
class B{
public:
B(){
cout<<"B::B"<<endl;
}
~B(){
cout<<"B::~B"<<endl;
}
};
~A(){
cout<<"A::~A"<<endl;
}
};
class C{
public:
C(){
cout<<"C::C"<<endl;
}
class D{
public:
D(){
cout<<"D:"<<endl;
}
~D(){
cout<<"D::~D"<<endl;
}
};
~C(){
cout<<"C::~C"<<endl;
}
};
class A::B : public C:{
public:
A::B() {
cout<<"A::B::A::B"<<endl;
}
~A::B(){
cout<<"A::B:~A::B"<<endl;
}
};
int main(){
A::B abObj;
return 0;
}
Pls guide !
- Wg