In my class, I have a std::vector<node*>children member variable.
I want to overload the index operator so that I can easily index one of the nodes.
Here is my slowdown class for this function:
node* operator[](int index);
Here is my class definition for this function:
node* class_name::operator[](int index){
return children[index];
}
However, this function does not seem to return a pointer, as I had hoped.
Here is a function that gives me problems:
void Print_Tree(node* nptr, unsigned int & depth){
if (NULL == nptr) {
return;
}
for (int i = 0; i < nptr->Number_Of_Children(); ++i){
Print_Tree(nptr[i],depth+1);
}
return;
}
The error I get is:
error: cannot convert 'node to' node * on recursive call
I donβt understand why it returns node to me when I want a pointer to node.
Is there something wrong with my overloaded function?
I tried dereferencing node in a recursive call:
Print_Tree(*nptr[i],depth+1);
Print_Tree(*(nptr[i]),depth+1);
Print_Tree(nptr->[i],depth+1);
to no avail!
What am I doing wrong?