我正在尝试为某些给定的点创建Voronoi图。每个点都有不同的属性,我想将其表示为颜色。为了用Boost Point概念映射我自己的Point结构,我写了一些代码。我有以下设置:其他结构中的结构构造函数
struct Point {
double a;
double b;
Point(double x, double y) : a(x), b(y) {}
};
// This Point structure is mapped to Boost Point concept. Code emitted
我有另一种结构:
struct Point_Collection {
Point xy(double x, double y);
short color;
};
Visual Studio创建一个自动定义为:
Point Point_Collection::xy(double x, double y)
{
return Point();
}
现在,如果我尝试实例化对象Point_collection为:
std::vector<Point_Collection> *test;
test = new std::vector<Point_Collection>();
Point_Collection xy_color;
for (int i = 0; i < 5000; i++) {
xy_color.xy(rand() % 1000, rand() % 1000);
xy_color.color = rand() % 17;
test->push_back(xy_color);
}
我收到一个错误。
error C2512: 'Point': no appropriate default constructor available
有人可以指出我为什么会发生这种情况吗?
你得到了什么错误? – MKR
Point xy(double x,double y)的用途是什么;'作为'Point_Collection'成员的一部分的声明是什么?为什么不能只声明'Point xy'。 – MKR
'xy'是一个成员函数,你必须写'xy_color.xy(.....);'。并提供函数的主体 –