View Single Post
Old 05-09-2004, 08:22 AM   #2 (permalink)
Pragma
I am Winter Born
 
Pragma's Avatar
 
Location: Alexandria, VA
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.

Perhaps a better idea:
Code:
class Dog {
protected:
    int array[2];
public:
     inline void print_array() {
          cout << array[0] << endl << array[1] << endl;
     }
};

class Collie : public Dog {
public:
 Collie() { // override constructor
   array[0] = 5;
   array[1] = 6;
  }
};

class Spaniel : public Dog {
public:
  Spaniel() {
     array[0] = 7;
     array[1] = 8;
  }
};

int main() {
  Collie c;
  Spaniel s;
  c.print_array();
  s.print_array();
  return 0;
}
I'm still not really sure what your code even attempts to do, but hopefully that helps.
__________________
Eat antimatter, Posleen-boy!

Last edited by Pragma; 05-09-2004 at 08:29 AM..
Pragma is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62