1:在函数中调用拷贝构造函数
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
vector<pair<int, PII>> colume;
const long long N = 10010;
int arr[N][N];
vector<PII> a;
int cnt = 0;
class MyGO {
string name;
int age;
string personality;
public:
void x() {
return;
}
};
class Myclass{
public:
Myclass(int n){number = n; }
Myclass(const Myclass& other) {
number = other. Number;
cout << "a";
}
private:
int number;
};
void fun(Myclass p) {//调用一次,如果将p修改为引用形式不会调用拷贝构造函数
return;
}
int main() {
MyGO MyGo;
MyGo.x();
Myclass obj1(10),obj2(0);
Myclass obj3(obj1);
fun(obj3);
return 0;
}
函数开始时就会被拷贝入函数中