Inheriting static variables

Hey everyone,

I was wondering if there is a way to inherit static variables, but to have them different for each child class.

Say I have the static variable "foo" which I need to use in a method that is from the parent class, but I want the value of "foo" to be different in every child class, yet still be static.
Defining a member of a derived class with the same name as a member of the base class (except virtual functions) hides the name of the entity in the base class. So you will have two different objects with the same name; one in the base class and other in the derived class.
There is nothing like virtual static variables in C++. Another way to do it is to have a virtual function that returns the correct (static) object.
^this. The point of static function or variable in a class is to easier group and therefore access something related to the inheriting class.
Mhm... I am having a bunch of classes that inherit from a 'block' class, and they all need to have their IDs in them... it would be nice to just put the get_id method in the parent class, but another way that I could do it is by just putting the block ID in the public domain and accessing the variable directly instead of through a function.. meh
Last edited on
Topic archived. No new replies allowed.