我正在嘗試爲某些給定的點創建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(.....);'。並提供函數的主體 –