C++ 拷贝构造函数和赋值操作符别忘了基类 #include "StdAfx.h" #include <iostream> using namespace std; class A { public: A( ){ cout << "A()" << endl ; }; A( const A & oth ){ cout << "A(const A&oth)" << endl ; }; A & operator= ( const A & oth ) { cout << "A & operator= ( A & oth )" << endl ; return *this ; } int data ; } ; class CC : public A { public: CC() { cout << "CC() " << endl ; } CC( const CC & oth ) :A(oth) { cout << "CC( const CC & oth )" << endl ; } CC & operator= ( const CC & oth ) { A::operator=(oth) ; cout << "CC & operator= ( const CC & oth ) " << endl ; return *this ; } int ccdata ;// 2*4 + 8 }; int main() { CC cc ; cout << endl ; CC sec ; cout << endl ; sec = cc ; cout << endl ; return 0 ; }