Quote:
Originally posted by Pragma
Static variables in classes don't work the same as static variables in C. A static variable in C++, declared as a class member, means that it is shared amongst all instances of the class.
|
Thanks for the help - but whilst your code does what I was trying to do, I'm quite keen to use C++ static variables (and, ideally, consts) so that there isn't an excessive waste of memory by having an extra copy of the array for each instance of Collie or Spaniel.
The only way I've found to do it so far is to declare the array as static within each derived class, and have a pointer variable in the base class which is set by the constructor function. Whilst that only wastes one 'int' per instance, it doesn't seem to take advantage of the const-ness of the data, and seems to be the Wrong Way of doing things...