Relative Content

Tag Archive for c++inheritancestaticsingleton

How can I avoid calling a static function (and call a base member function instead)?

I have a singleton instance of a class which derives from a base call. So far, so good. Derived has a static function fun, while Base has a member function fun (don’t ask). Obviously, calling singleton->fun() in Derived::fun() create an infinite recursion ending in stack overflow. I managed to avoid that by calling ((Base*)singleton)->fun() instead: