#include<iostream>
#include<string>
using namespace std ;
class CBase
{
protected:
char *ch ;
public:
CBase( char *x )
{
ch = new char[20] ;
strcpy( ch , x ) ;
}
virtual void fun() = 0 ;
virtual void fun1() //虚函数
{
cout << x << endl ;
}
{
cout << ch << endl ;
}
~CBase()
{
delete[]ch ;
cout << "~CBase()" << endl ;
}
};
class CDerived:public CBase
{
protected:
char *ch ;
public:
CDerived ( char *x , char*y ):CBase(y)
{
ch = new char[20] ;
strcpy( ch , x ) ;
}
void fun1()// {cout<<x<<endl;}
{
cout << ch << endl ;
}
virtual ~CDerived()
{
delete[]ch ;
cout << "~CDerived()" << endl ;
}
};
int main()
{
CBase obj1("Hello") , *p ;
p = &obj1 ;
p->fun1() ;
p->fun() ;
p=new CDerived("China","Hello") ;
p->fun1() ;
p->fun() ;
delete p ;
return 0 ;
}
不知道 http://zhidao.baidu.com/question/427555918.html?quesup2&oldq=1