【发布时间】:2020-03-19 13:23:00
【问题描述】:
我正在尝试使用指向数组的指针创建每个节点,该数组将包含对象类中的其他节点(相同类型)。
class node
{
public:
node(int degree, bool visited, int xpos, int ypos);
node *adjList = new node[9];
float * valueList = new float[832];
int size = 0;
int adjSize = 0;
int xpos, ypos;
int degree = 0;
bool visited;
};
线是
node *adjList = new node[9];
这不起作用。这是说这个声明没有匹配的构造函数。我尝试创建一个空的构造函数,但这会破坏我的代码。
可视化是这样的:
节点: [0] ---> [ [3][4]][8] ]
【问题讨论】:
-
没错。
new node[9]创建九个node对象和默认构造它们。问题是没有node默认构造函数。
标签: c++ arrays object constructor adjacency-list