小记:运行环境:vs 2013 c++ win32 console application
#include "stdafx.h" #include <iostream> #include <cstdlib> using namespace std; class A{ public: A(){ cout << "A::A()" << endl; } A(A&){ cout << "A::A(A&)" << endl; } A& operator=(A& a) { cout << "operator=(A&)" << endl; // *this = a; // endless loop return *this; } }; int _tmain(int argc, _TCHAR* argv[]) { // A a, b; // two default constructor // a = b; // one assignment // A a; // one default constructor // A b = a; // one copy constructor A c = A(); // one default constructor, no temporary project system("pause"); return 0; }
Author:角落里的一条狗
本文通过一个C++类实例,详细解析了默认构造函数、拷贝构造函数及赋值运算符重载的调用场景与实现过程,帮助读者深入理解C++中对象的创建与赋值机制。
324

被折叠的 条评论
为什么被折叠?



