CPP多态
// cqqtest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Virtual{
public:
virtual void foo(){
cout<<"Virtual"<<endl;
}
};
class bbb: public Virtual{
public:
void foo(){
cout<<"bbb"<<endl;
}
};
class ccc: public bbb{
private:
void foo(){
cout<<"ccc"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Virtual &vt =ccc();
vt.foo();//output "ccc"
ccc &cc= ccc();
cc.Virtual::foo();
getchar();
return 0;
}
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Virtual{
public:
virtual void foo(){
cout<<"Virtual"<<endl;
}
};
class bbb: public Virtual{
public:
void foo(){
cout<<"bbb"<<endl;
}
};
class ccc: public bbb{
private:
void foo(){
cout<<"ccc"<<endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Virtual &vt =ccc();
vt.foo();//output "ccc"
ccc &cc= ccc();
cc.Virtual::foo();
getchar();
return 0;
}