Milan Novaković
Milan Novaković

Reputation: 351

If I'm using a private struct, how do I declare it as an argument for the member functions listed above as public?

VS is not happy with the "Node*" argument for "makeEmptyHelper" because it does not 'see' the struct I guess.

public:
    void makeEmpty(); // make the tree empty so isEmpty returns true 
    void makeEmptyHelper(Node*);

private:
    struct Node {
        NodeData* data; // pointer to data object 
        Node* left; // left subtree pointer 
        Node* right; // right subtree pointer 
    };
    Node* root; // root of the tree 

Upvotes: 0

Views: 101

Answers (3)

user2752467
user2752467

Reputation: 844

You can't do that. I see two possible things you're trying to accomplish:

  • Have makeEmptyHelper be accessible publicly but hide the contents of struct Node. In that case, you should either declare the fields of struct Node as private, or declare struct Nodeas public but only define its members in your implementation file.

  • Have makeEmptyHelper be a helper function for another member function. In that case, make it private.

Upvotes: 1

Manex
Manex

Reputation: 538

The Node struct is an argument of a public method of your class.

Therefore the Node struct is something that will be public outwards.

So the Node struct shall be public.

Upvotes: 0

nvoigt
nvoigt

Reputation: 77285

That's correct. You cannot have a function publicly available while it's argument is private. Either make the type of the argument public as well or make the method private.

Upvotes: 1

Related Questions