构造函数 虚函数 虚析构函数

#include <stdio.h>


class Base
{
public:
Base(){printf("call Base\n");}
virtual ~Base(){printf("call ~Base\n");}
virtual int cmd_id(){return m_cmd_id;}
public:
int m_cmd_id;
};


class Derive:public Base
{
public:
Derive(){m_cmd_id = 11;printf("call Derive\n");}
virtual ~Derive(){printf("call ~Derive\n");}
};


int main(int argc,char *argv[])
{
printf("%d\n",Derive().cmd_id());
printf("some where\n");
return 0;

}

打印结果:

call Base
call Derive
11
call ~Derive
call ~Base
some where

你可能感兴趣的:(cmd,Class,include)