Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • Well, the constructor of derived is private, so the class will be tricky to use, but I don't think that's the problem. Why not try it using a simpler access? For example, a derived class function that just returns x (Hint: you won't need to specify base:: to access it) Commented Aug 13, 2018 at 14:28
  • Does stackoverflow.com/questions/477829/… answer your question? It's very similar. Commented Aug 13, 2018 at 14:30
  • 3
    why to not use just : g = &x; ?
    – Simion
    Commented Aug 13, 2018 at 14:30
  • @SebastianRedl the question you link is about calling a protected method on another instance, which isnt exactly the case here Commented Aug 13, 2018 at 14:32
  • @user463035818 The reasoning is the same though. You try to access a protected member through an access path that is not your class. Which is why songyuanyao's answer works. Commented Aug 13, 2018 at 14:36