1

I have a node class and a derived beta node class. My node class has a method to return a shared_ptr of this. Here is essentially the node class:

class Node {
   int start;
   int stop;
   std::string data;

protected: 
   inline std::shared_ptr<Node> getSPNode() {return make_shared<Node>(this);}

public:
   //some other stuff
};

class BetaNode : public Node {
   int location;

public:
   BetaNode(int curr, int next);
   //some other stuff
};

There is some other stuff going on with these classes but my issue is with the getSPNode() method. When I call it like this I get a "'getSPNode' is a protected member of 'Node'" error. I thought that BetaNode would have access to this because it is a derived member.

void someFunction(shared_ptr<Node> someNode, int curr, int next) {
   shared_ptr<BetaNode> beta(new BetaNode(curr, next));
   if (beta->getSPNode() == someNode)
      //do stuff
}

EDIT: Sorry for the duplicate, found an answer here right after I posted this: Why can't I access a protected member from an instance of a derived class?

Community
  • 1
  • 1
zeus_masta_funk
  • 1,388
  • 2
  • 11
  • 34

1 Answers1

1

You are trying to access the protected method outside of the class hierarchy. You would need to make it a public method for this to work.

GWW
  • 43,129
  • 11
  • 115
  • 108