#include
#include
#pragma hdrstop
using namespace std;
//---------------------------------------------------------------------------
class A
{
private:
// virtual void __fastcall virtual_private_pure()=0;
// void __fastcall private_pure()=0;
virtual void __fastcall virtual_private_A(){cout << "virtual_private_A" << endl;};
void __fastcall private_A(){cout << "private_A" << endl;};
protected:
virtual void __fastcall virtual_protected_pure()=0;
// void __fastcall protected_pure()=0;
virtual void __fastcall virtual_protected_A(){cout << "virtual_protected_A" << endl;};
void __fastcall protected_A(){cout << "protected_A" << endl;};
public:
virtual void __fastcall virtual_public_pure()=0;
// void __fastcall public_pure()=0;
virtual void __fastcall virtual_public_A(){cout << "virtual_public_A" << endl;};
void __fastcall public_A(){cout << "public_A" << endl;};
void A_get_private_A(){ private_A(); }
void A_get_virtual_private_A(){ virtual_private_A(); }
virtual void get_private_A(){ private_A(); }
virtual void get_virtual_private_A(){ virtual_private_A(); }
void get_private_A2(){ private_A(); }
void get_virtual_private_A2(){ virtual_private_A(); }
virtual void get_private_A3(){ private_A(); }
virtual void get_virtual_private_A3(){ virtual_private_A(); }
void void get_private_A4(){ private_A(); }
void void get_virtual_private_A4(){ virtual_private_A(); }
};
class B : public A
{
private:
// virtual void __fastcall virtual_private_pure()=0; //no supported
// void __fastcall private_pure()=0; //no supported
//以下2個要宣告,否則後面func呼叫會失敗,有宣告仍可以達到繼承
virtual void __fastcall virtual_private_A(){cout << "virtual_private_B" << endl;};
void __fastcall private_A(){cout << "private_B" << endl;};
protected:
virtual void __fastcall virtual_protected_pure(){cout << "virtual_protected_pure B" << endl;};
// void __fastcall protected_pure()=0; //no supported
virtual void __fastcall virtual_protected_A(){cout << "virtual_protected_B" << endl;};
void __fastcall protected_A(){cout << "protected_A" << endl;};
public:
virtual void __fastcall virtual_public_pure(){cout << "virtual_public_pure B" << endl;};
// void __fastcall public_pure()=0; //no supported
virtual void __fastcall virtual_public_A(){cout << "virtual_public_B" << endl;};
void __fastcall public_A(){cout << "public_B" << endl;};
void B_get_private_A(){ private_A(); }
void B_get_virtual_private_A(){ virtual_private_A(); }
virtual void get_private_A(){ private_A(); }
virtual void get_virtual_private_A(){ virtual_private_A(); }
void get_private_A2(){ private_A(); }
void get_virtual_private_A2(){ virtual_private_A(); }
void get_private_A3(){ private_A(); }
void get_virtual_private_A3(){ virtual_private_A(); }
virtual get_private_A4(){ private_A(); }
virtual get_virtual_private_A4(){ virtual_private_A(); }
};
#pragma argsused
int main(int argc, char* argv[])
{
B b;
A *pA = dynamic_cast(&b);
//private calling exported B-func , exported A-func , privated-func
b.B_get_private_A(); // B non-virt x non-virt
b.B_get_virtual_private_A(); // B non-virt x virt
b.get_private_A(); // B virt virt non-virt
b.get_virtual_private_A(); // B virt virt virt
b.get_private_A2(); // B non-virt non-virt non-virt
b.get_virtual_private_A2(); // B non-virt non-virt virt
b.get_private_A3(); // B non-virt virt non-virt
b.get_virtual_private_A3(); // B non-virt virt virt
b.get_private_A4(); // B virt non-virt non-virt
b.get_virtual_private_A4(); // B virt non-virt virt
pA->A_get_private_A(); // A x non-virt non-virt
pA->A_get_virtual_private_A(); // B x non-virt virt(h)
pA->get_private_A(); // B virt(x) virt(h) non-virt
pA->get_virtual_private_A(); // B virt(x) virt(h) virt
pA->get_private_A2(); // A non-virt(x) non-virt non-virt
pA->get_virtual_private_A2(); // B non-virt(x) non-virt virt(h)
pA->get_private_A3(); // B non-virt(x) virt(h) non-virt
pA->get_virtual_private_A3(); // B non-virt(x) virt(h) virt
pA->get_private_A4(); // A virt(x) non-virt non-virt
pA->get_virtual_private_A4(); // B virt(x) non-virt virt(h)
return 0;
}
//---------------------------------------------------------------------------
2011年7月12日 星期二
C++ 繼承測試
訂閱:
張貼留言 (Atom)
文章分類
- 爬山 (3)
- 參考文章 (3)
- 鳥事 (5)
- 報稅 (1)
- AIX (2)
- ajax (1)
- BCB (3)
- C/C++ (2)
- cloudera (3)
- DISK (1)
- ftp (1)
- Fuse (2)
- gdb (2)
- hadoop (13)
- hdfs (8)
- HPC (2)
- hypertable (12)
- iOS (1)
- iscsi (1)
- JAVA (2)
- KFS (5)
- kickstart (1)
- KVM (2)
- LAMP (2)
- linux (2)
- Lion (1)
- LVM (2)
- mapreduce (3)
- mpi (3)
- mpich2 (4)
- msgpack (2)
- mysql (2)
- nfs (1)
- openmp (2)
- OS (1)
- OSX (2)
- others (5)
- PBS (1)
- performance_tuning (3)
- php (3)
- phplist (3)
- programming (27)
- REST (2)
- RHCA (6)
- rhel (13)
- rhel6 (4)
- scp (1)
- shell_scripts (2)
- snowleopard (2)
- Solaris (6)
- ssh (1)
- syslog (1)
- t-442-1 (4)
- torque (1)
- ubuntu (2)
- VNC (1)
- watercolor (5)
- windows (1)
- yum (1)
沒有留言:
張貼留言