[日期:2009-06-22] | 来源:中嵌信息 作者:chinaeda-news | [字体:大 中 小] |
class Empty { public: Empty(); // 缺省构造函数 Empty(const Empty&); // 拷贝构造函数 ~Empty(); // 析构函数 Empty& perator=(const Empty&); // 赋值运算符 Empty* operator&(); // 取值运算符 const Empty* operator&() const; // 取值运算符 }; |
class StringBad { private : char * str; int len; public : StringBad( const char * s); StringBad(); ~ StringBad(); } ; |
StringBad::StringBad( const char * s) { len = std::strlen(s); str = new char [len + 1 ]; } StringBad::StringBad() { len = 4 ; str = new char [ 4 ]; } StringBad:: ~ StringBad() { delete [] str; } |
#include <iostream></iostream> #include <string></string> struct X { template<typename T> X( T& ) { std::cout << "This is ctor." << std::endl; } template<typename T> X& perator=( T& ) { std::cout << "This is ctor." << std::endl; } }; void main() { X a(5); X b(10.5); X c = a; c = b; } |
class X { public: X(const X&); X(X&); // OK }; |
class X { public: X(); X(X&); }; const X cx; X x = cx; // error |
struct X { template<typename T> X( const T& ); // NOT copy ctor, T can't be X template<typename T> perator=( const T& ); // NOT copy ass't, T can't be X }; |
通信人家园 (https://www.txrjy.com/) | Powered by C114 |