问题相关代码,请勿粘贴截图
#include
#include
using namespace std;
class Object {
public:
Object() {
std::cout << "build this object!" << std::endl; }
Object(Object& obj) {
std::cout << "copy this object! " << std::endl;
}
virtual ~Object() {
std::cout << "destruct this object! " << std::endl; }
};
//int Object::num=0;
void f(Object obj){ }
int main() {
Object obj;
// function calling
f(obj);
// vector
std::vector v;
v.push_back(obj);
return 0;
}
编译时提示“rror C2558: class 'Object' : no copy constructor available”,注释掉复制构造函数,编译就能通过,不报错,这是什么原因