I’m creating little GUI for my OpenGL game. I’ve got two base classes Widget and Container. Widget class has methods like setPosition(x,y), setSize(w,h),… These methods should be visible only for classes derived from Container.
Edit: I can do it with friend and wrapper methods, but I’d like to do it without wrappers.
In case the suggestion was not clear from the comment, you can consider creating an interface with that subset of the methods and use private inheritance in
Widget. Then use a protected (a single operation) inContainerthat would obtain that private interface for classes derived from it:The main difference with the forwarding options is that this scales better with the number of functions and is more maintainable (no need to update N-forwarders, just the accessor to the proper interface).
From a high level design point of view, a
Widgetis notDrawablein general, it is onlyDrawablefrom the context ofWidgetorContainer.