C++ 拷貝建構函式和賦值操作符別忘了基類
#include "StdAfx.h"<br />#include <iostream><br />using namespace std;</p><p>class A {<br />public:<br />A( ){ cout << "A()" << endl ; };<br />A( const A & oth ){ cout << "A(const A&oth)" << endl ; };</p><p>A & operator= ( const A & oth ) {<br />cout << "A & operator= ( A & oth )" << endl ;<br />return *this ;<br />}<br />int data ;<br />} ;</p><p>class CC : public A {<br />public:<br />CC() {<br />cout << "CC() " << endl ;<br />}</p><p>CC( const CC & oth )<br />:A(oth)<br />{<br />cout << "CC( const CC & oth )" << endl ;<br />}</p><p>CC & operator= ( const CC & oth ) {<br />A::operator=(oth) ;<br />cout << "CC & operator= ( const CC & oth ) " << endl ;<br />return *this ;<br />}<br />int ccdata ;// 2*4 + 8<br />};</p><p>int main()<br />{<br />CC cc ;<br />cout << endl ;<br />CC sec ;<br />cout << endl ;</p><p>sec = cc ;<br />cout << endl ;<br />return 0 ;<br />}<br />