passing pointers

Hey guys I was just writing a simple tree structure that returns a node pointer when a node is created. The compiler will not let me do so as it says that "Error: identifier Node is undefined" at line 2

here is the part of the tree.cpp
1
2
3
4
5
6
7
8
Node RBtree::*createNode(int x){
	Node* node = new Node;
	node->parent = NULL;
	node->lchild = NULL;
	node->rchild = NULL;
	node->data = x;
	node->color = 'r';
}


with part of tree.h
1
2
3
4
5
6
7
8
9
10
11
    private:
        struct Node{
           Node* parent;
           Node* lchild;
		   Node* rchild;
           int data;
		   char color;
        };
        Node* root;
    public:
        Node *createNode(int);


Any feedback would be appreciated thank you.
The struct is private. You can't return private types from public functions. How would the caller know about a private type?
I thought that since I used RBtree:: it had access to the Node struct?
After moving it into the public field I have the same problem
After moving it into the public field I have the same problem
In this case, it's because you only enter the RBtree namespace after the BRtree:: part of the definition.
1
2
3
//You can use 'Node' to refer to 'RBtree::Node' only after this point.
//                    v
RBtree::Node *RBtree::createNode(int x){ //... 
Oh ok I got it.
Thank you!
Topic archived. No new replies allowed.