#include<iostream> using namespace std; class A{ public: A(int n); A(A& b); public: int v; }; A::A(int n):v(n){ } A::A(A&b){ v = b.v; cout <<"hello world"<<endl; } A func(){ A b(4); return b; } int main() { cout << func().v<<endl; return 0; }
以上函数运行时,没有输出“hello",也就是没有调用我写的复制构造函数。
按理说,返回一个类,是会调用复制构造函数的呀?希望能解答一下
相关分类