我正在尝试做一个小应用程序来计算给定图的一些路径。使用私人变量初始化数组
我创建了一个类来处理简单的图表,如下所示:
class SimpleGraph {
int _nbNodes;
int _nbLines;
protected:
int AdjMatrix[_nbNodes, _nbNodes]; //Error happens here...
int IncMatrix[_nbNodes, _nbLines]; //...and here!
public:
SimpleGraph(int nbNodes, int nbLines) { this->_nbNodes = nbNodes - 1; this->_nbLines = nbLines - 1; };
virtual bool isSimple();
};
在编译时,我得到两个保护成员声明的错误。
我不明白什么是错的,因为只有一个构造函数将这些值作为参数。因此,它们不能被初始化。
我在这里错过了什么?
您必须使用动态内存分配和'new'关键字 – acrilige 2013-03-28 07:03:39
@acrilige使用封装类(通常是'std :: vector')比手动处理分配,复制安全和异常安全强烈得多。 – Angew 2013-03-28 07:45:43