c++拷贝函数的调用 一调用就报错 然后之前正确的代码也运行不了了 照着b站视频编写的 不知道哪里错了 一个字一个字对着敲的
代码如下:
```c++
#include<iostream>
using namespace std;
class person {
public:
person() {
cout << "无参构造函数!" << endl;
}
person(int age) {
m_age = age;
cout << "有参构造函数!" << endl;
}
person(const person& p) {
m_age = p.m_age;
cout << "拷贝构造函数!" << endl;
}
~person() {
cout << "析构函数!" << endl;
}
int m_age;
};
void test01() {
person p1(20);
person p2(p1);
}
int main() {
test01();
system("pause");
return 0;
}
```
我这跑了一下没有问题,清理一下工程试试:
图片里错误提示的代码段,和后面的代码段不是同一项目的?后面的代码段没什么问题,正常。
代码逻辑没啥问题,可能是环境问题,看网上有这么说的:
修改Runtime Library,由MDd改为MTd即可 ,试试吧。是VS环境么