一个编译错误,求大神
#include <iostream>
#include <string>
#include<vector>
using namespace std;
struct Point
{
Point(int a,int b):x(a),y(b){}
int const x;
int const y;
};
int main()
{
vector<Point> a;
Point p(0,0);
a.push_back(p);
return 0;
}
出现编译错误:
ctest.cpp
d:\programfiles\microsoft visual studio\vc98\include\xutility(39) : error C2582: 'Point' : 'operator =' function is unavailable
d:\programfiles\microsoft visual studio\vc98\include\vector(170) : see reference to function template instantiation 'void __cdecl std::fill(struct Point *,struct Point *,const struct Point &)' being compiled
d:\programfiles\microsoft visual studio\vc98\include\xutility(25) : error C2582: 'Point' : 'operator =' function is unavailable
d:\programfiles\microsoft visual studio\vc98\include\vector(174) : see reference to function template instantiation 'struct Point *__cdecl std::copy_backward(struct Point *,struct Point *,struct Point *)' being compiled
执行 cl.exe 时出错.
[解决办法]
#include <iostream>
#include <string>
#include<vector>
using namespace std;
struct Point
{
Point(int a,int b):x(a),y(b){}
int x;
int y;
};
int main()
{
vector<Point> a;
Point p(0,0);
a.push_back(p);
return 0;
}
[解决办法]
int const x;
int const y;
//改成
int x;
int y;
[解决办法]
另外需要给Point重载void operator=(const Point&)
[解决办法]
为Point写一个拷贝构造函数试试