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?