Papers/programming

constructor & destructor calling in inheritance

tomato13 2013. 11. 19. 09:03

// CParent

class CParent

{

public:

    CParent()

    {        

        printf("CParent constructor\n");

    }


    ~CParent()

    {

        printf("CParent destructor\n");

    }


// CChild

class CChild : public CParent

{

public:

    CChild() 

    {

        printf("CChild constructor\n");

    };


    ~CChild()

    {        

        printf("CChild destructor\n");

    }


// main function

int main(void)

{

CChild* pObj = new CChild();

    delete pObj;


return 0;

}


=>


// result

CParent constructor

CChild constructor

CChild destructor

CParent destructor

'Papers > programming' 카테고리의 다른 글

declare an object in switch logic  (0) 2013.11.21
void pointer  (0) 2013.11.21
What is the difference between singleton and static class?  (0) 2013.07.16
이차원 배열선언  (0) 2013.05.17
union vs. struct  (0) 2010.03.31