c – std :: vector error C2582:’operator =’函数不可用
发布时间:2020-12-16 06:47:04 所属栏目:百科 来源:网络整理
导读:我使用简单的向量push_back到类型A的对象 并得到这个错误, 这是我的代码: class A { public: A(int a,int b,int c);};#include "A.h"................std::vectorA* vec_objects = new std::vectorA();while(....some condition ...) { A a(1,2,3) vec_obje
我使用简单的向量push_back到类型A的对象
并得到这个错误, 这是我的代码: class A { public: A(int a,int b,int c); }; #include "A.h" .... .... .... .... std::vector<A>* vec_objects = new std::vector<A>(); while(....some condition ...) { A a(1,2,3) vec_objects->push_back(a); } 收到此错误: c:program filesmicrosoft visual studio 9.0vcincludexutility(3159) : error C2582: 'operator =' function is unavailable in 'A' 1> c:program filesmicrosoft visual studio 9.0vcincludexutility(3187) : see reference to function template instantiation 'void std::_Fill<A*,_Ty>(_FwdIt,_FwdIt,const _Ty &)' being compiled 1> with 1> [ 1> _Ty=A,1> _FwdIt=A * 1> ] 1> c:program filesmicrosoft visual studio 9.0vcincludevector(1231) : see reference to function template instantiation 'void std::fill<A*,1> _FwdIt=A * 1> ] 1> c:program filesmicrosoft visual studio 9.0vcincludevector(1153) : while compiling class template member function 'void std::vector<_Ty>::_Insert_n(std::_Vector_const_iterator<_Ty,_Alloc>,unsigned int,const _Ty &)' 1> with 1> [ 1> _Ty=A,1> _Alloc=std::allocator<A> 1> ] 1> 我做错了什么? 解决方法
您需要将operator =和copy-constructor添加到A类
class A { public: A(int a,int c); A(const A& element); A& operator=(const A& element); //which needs definition }; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |