Hi , As in my code .. only the destructor of the base class is being called .
i was assuming that the destructor of the derived class will be called first then the destructor of the base class .. but it is not happning .. i am not able to understand why .. please explain me this . Any help is appreciated .
thanks in advance ..
#include "stdafx.h"
#include <iostream>
usingnamespace std;
class CTestA
{
private:
int a ;
public:
CTestA() { a = 5 ; cout<<"\n This the testA constructor ";}
virtual ~CTestA() { cout<<"\n This the testA destructor "; }
virtualvoid Print() ;
};
void CTestA::Print()
{
cout<<"\n Print value of A = "<<a ;
}
class CTestB : public CTestA
{
private :
int b ;
public :
CTestB() : CTestA() { b = 10 ; cout << "\n This the constructor of test B " ; }
~CTestB() { cout<<"\n This is the destructor of the TestB and the value of b = "<<b ;}
void Print();
};
void CTestB::Print()
{
cout<<"\n This is the print function of TestB ";
}
//using the multiple inheretance .
class CTestC : public CTestA
{
private:
int c ;
public:
CTestC() { c = 15 ; "\n This is the constructor of the Test C "; }
~CTestC() {"\n This is the destructor of the CTest C "; }
void Print() ;
};
void CTestC::Print()
{
cout<<"\n This is the print of the CTest C having the value of c = " <<c ;
}
int _tmain(int argc, _TCHAR* argv[])
{
CTestA *test = new CTestC() ;
test->Print();
delete test ;
return 0;
}
CTestC() { c = 15 ; "\n This is the constructor of the Test C "; } // <- missing cout
~CTestC() {"\n This is the destructor of the CTest C "; } // <-same