- 论坛徽章:
- 0
|
#include <stdio.h>
class CA
{
private:
int iA;
public:
CA( int a): iA(a) {}
CA( CA &obj)
{
iA = obj.iA;
}
void Print2( void)
{
printf( "iA = %d\n", iA);
}
};
class CB: public CA
{
private:
int iB;
public:
CB( int a, int b): iB(b), CA(a) {}
CB( CB &obj) : CA(obj)
{
iB = obj.iB;
}
void Print( void)
{
printf( "iB = %d\n", iB);
Print2();
}
};
int main( int argc, char **argv)
{
CB oB1(1,2);
CB oB2( oB1);
oB2.Print();
while(1);
return 0;
}
因为基类CA定义了拷贝构造函数,
所以编译器不会再定义二进制拷贝的语义,所以CB的拷贝构造函数要自己指定调用(编译器不会帮你做) |
|