std :: vector< A>错误C2582:'operator ='函数不可用 [英] std::vector<A> error C2582: 'operator =' function is unavailable in
本文介绍了std :: vector< A>错误C2582:'operator ='函数不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
im使用简单的向量push_back到A类型的对象
并得到此错误
这是我的代码:
im using simple vector push_back to object of Type A and getting this error , this is my code :
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 files\microsoft visual studio 9.0\vc\include\xutility(3159) : error C2582: 'operator =' function is unavailable in 'A'
1> c:\program files\microsoft visual studio 9.0\vc\include\xutility(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 files\microsoft visual studio 9.0\vc\include\vector(1231) : 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 files\microsoft visual studio 9.0\vc\include\vector(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>
我做错了什么?
推荐答案
您需要为A类添加operator =和copy-constructor
You need to add operator= and copy-constructor to class A
class A
{
public:
A(int a,int b,int c);
A(const A& element);
A& operator=(const A& element); //which needs definition
};
这篇关于std :: vector< A>错误C2582:'operator ='函数不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文