【发布时间】:2015-10-09 20:59:20
【问题描述】:
我正在尝试用指针实现的列表列表创建一个 n 叉树,这是我的Tree 的实现:
class Tree{
public:
struct nodeSon{
struct node* node_ptr;
nodeSon* nextNodeSon_ptr;
};
struct node{
char label;
node* nextNode_ptr;
struct nodeSon* nSon;
};
node* root;
void AddSon(int i, node n, char l); //Adds a son with label l to n at i position
};
当我尝试实现Tree::AddSon()时出现问题:
void Tree::AddSon(int i, nodo n, char l){
node* nextPtr = root->nextNode_ptr;
node* newNode = new node();
newNode->label= l;
root->nextNode_ptr = newNode;
newNode->nextNode_ptr = nextPtr;
node* it = root;
while (it != &n) {
it = it->nextNode_ptr;
}
nodeSon* it2 = it->nSon;
int counter = 1;
while (contador != i) {
it2 = it2->sigNodoHijo_ptr;
}
nodeSon* nextPtrNH = it2->nextNodeSon_ptr;
nodeSon* newNodeNH = new nodeSon();
newNodeNH->node_ptr = newNodo; //error indication at this line
it2 = newNodeNH;
newNodoNH->nextNodeSon_ptr = nextPtrNH;
.
.
.
}
我在尝试构建它时收到此错误:
Tree.cpp:110:27: error: cannot convert 'Tree::node*' to 'node*' in assignment
- 为什么会这样?
- 我该如何解决这个问题?
【问题讨论】:
标签: c++ pointers struct tree mingw