I want to access my Node struct in order to create a function that generates a new node. To do so i thought that the only way to do it is to create a constructor inside my struct and to call the constructor in my CreateNode function. However i get an error :[Error] 'struct BS::Node' is protected. An ovious sollution to the problem is to make struct Node public however i want to ask if there is another way to access my struct and keep it private.
Header file
class BS
{
public:
BS(); //constructor
protected:
struct Node{
int data;
Node* left;
Node* right;
Node(int d,Node* lf ,Node* ri)
:data(d),left(lf),right(ri){}
};
Node* root;
Node* CreateNode(int data);
};
CPP
BS::BS(){
root=NULL;
}
BS::Node* CreateNode(int data){
Node* new_node= new Node(0,NULL,NULL);
return new_node;
}