View Single Post
Old 05-09-2004, 10:59 PM   #7 (permalink)
cliche
Rookie
 
cliche's Avatar
 
Location: Oxford, UK
Thanks for the help, KnifeMissile, the compliment and the advice about smilies (I hadn't seen the option :) )
This is what I came up with myself - I'm not sure if it's just another instance of your result but it seems to work too:
Code:
class dog
{
 public:
  int const *numb;
  void print_data()
  { cout << *numb << "\n"; };
};


class collie : public dog
{
 public:
  static int const numb;
  collie(){dog::numb=&collie::int_numb;};
};
int const collie::int_numb=111;

class spaniel : public dog
{
 public:
  static int const int_numb;
  spaniel(){dog::numb=&spaniel::int_numb;};
};
int const spaniel::int_numb=555;
I've confusingly removed the arrays (when I realised it wasn't the fact it was an array that was the problem in the real code) and not bothered making int_numb private here. Any thoughts?

On reading around I've decided what I really was looking for was something like:
Code:
/* not valid C++ but I'd like it to be :) */
class dog
{
 public:
  virtual int numb;
  void print_data()
  { cout << numb << "\n"; };
};

class spaniel
{
public:
  static int const numb;
};

/* etc.... */
Thanks for all the help - C++ looks interesting once I can shoehorn it into my way of thinking...

EDIT to take Knifemissile's advice about const and data location... hope that's right!
__________________
I can't understand why people are frightened of new ideas. I'm frightened of the old ones. -- John Cage (1912 - 1992)

Last edited by cliche; 05-09-2004 at 11:08 PM..
cliche 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 63 64 65 66 67 68 69 70 71 72 73