#i nclude "stdio.h"
#i nclude "conio.h"
class Parent
{
public:
char data[20];
void Function1();
virtual void Function2(); // 这里声明Function2是虚函数
}parent; //类也可以这么搞?
void Parent::Function1()
{
printf("This is parent,function1\n");
}
void Parent::Function2()
{
printf("This is parent,function2\n");
}
class Child: public Parent
{
void Function1();
void Function2();
} child;
void Child::Function1()
{
printf("This is child,function1\n");
}
void Child::Function2()
{
printf("This is child,function2\n");
}
int main(int argc, char* argv[])
{
Parent *p; // 定义一个基类指针
if ( _getch()=='c' )
p=&child;
else
p=&parent;
p->Function1();
p->Function2();
return 0;
}
狐的传说
Cats萌萌
相关分类