【发布时间】:2014-02-18 01:18:08
【问题描述】:
我必须为一个班级制作一个十六进制板,但我的代码有问题。我的图表有一个板的二维节点向量。每个节点都有一个相邻节点的向量。我似乎无法将邻居节点分配到向量中。
节点类:
class node{
public:
string hex_type = "E";// empty to start
vector<node> neighbors;
int Xcoordinate;
int Ycoordinate;
class graph{
public:
int size;
graph() { this->size = 11; }
graph(int a){ this->size = a; }
vector<vector<node> > nodes;
void initialize(){
int x, y;
int max = this->size-1;
this->nodes = vector<vector<node> >(size, vector <node>(size));
for (x = 0; x < size; ++x){
for (y = 0; y < size; ++y){
//this->nodes[x][y] = node();
this->nodes[x][y].Xcoordinate = x;
this->nodes[x][y].Ycoordinate = y;
this->nodes[x][y].neighbors = vector<node>(6);
if ((x == 0) && (y == 0)){ this->nodes[x][y].neighbors[0] = this->nodes[x + 1][y]; }
}
}
}
};
我这里的打印语句只输出一串数字:-842150451
cout << this->nodes[0][0].neighbors[0].Xcoordinate;
【问题讨论】:
-
X坐标怎么样?