C++繼承的本質(zhì)
個(gè)人觀點(diǎn),有錯(cuò)誤之處,請(qǐng)批評(píng),謝謝.
測(cè)試代碼如下:
#include <iostream>
#include <typeinfo>
using namespace std;
class A
{
public:
A(){
strcpy(x,"A::x");
}
char x[20];
};
class B
{
public:
B(){
strcpy(x,"B::x");
}
char x[20];
};
class C:
public A,public B
{
public:
C(){
strcpy(x,"C::x");
}
char x[20];
};
int main(){
C c;
cout<<c.A::x<<endl;
cout<<c.B::x<<endl;
cout<<c.x<<endl;
system("pause");
return 0;
}
#include <typeinfo>
using namespace std;
class A
{
public:
A(){
strcpy(x,"A::x");
}
char x[20];
};
class B
{
public:
B(){
strcpy(x,"B::x");
}
char x[20];
};
class C:
public A,public B
{
public:
C(){
strcpy(x,"C::x");
}
char x[20];
};
int main(){
C c;
cout<<c.A::x<<endl;
cout<<c.B::x<<endl;
cout<<c.x<<endl;
system("pause");
return 0;
}
posted on 2010-10-23 17:57 天下 閱讀(225) 評(píng)論(0) 編輯 收藏 引用

