Quote:Original post by Waaayoff
I'm creating a GUI, and in my code, i have an abstract Control class. All controls (Panels, Buttons, Sliders etc..) derive from this class.
So what is in common between Controls that they need to be related like this?
Quote:Since i'm using polymorphism, i can't access functions of the derived class
You only lose access to these functions when you deliberately "forget" the type, by, e.g. putting the Controls in a container of Controls. I.e., actually "using" polymorphism.
I think something is confused in your design: either a given bit of code cares that a particular Control is a Panel, or it does not. If it does, it should not be trying to treat the Panel polymorphically. If it does not, it should not need access to Panel-specific information.
Quote:so i have to have a virtual function in the base class that interacts with the m_Visible member
Well... I can certainly see why you'd need some kind of code that interacts with it (otherwise it's just taking up space); but do you really need an accessor? What is the outside calling code going to do with the information about whether a Panel is visible or not? Why isn't the Panel doing something with that information instead (e.g. conditionally bailing out of its rendering)?
Quote:The problem however is that now i have to add a default functionality for this function
Well...
that should be the
least of your problems here. Are the other components visible or aren't they? This doesn't seem like it ought to be a hard question to answer.
But the point is, you need to think more about your design.