From: Raul C. <car...@lu...> - 2001-03-30 18:37:00
|
> I wonder how you define a pointer in a class that should be shared by all objects of that class. > In Java I know you use Static and the variable and its memory segment will be shared by all the objects. > How do you do this in C++? You just need to declare them static like in java. But it's a bit different to handle. an example for your bullet problem: in your .h file class Bullet { ... static BITMAP * graphic; }; in a .cpp file: BITMAP * Bullet::graphic = NULL; // this must be global, outside any functions. then in a function, any function, you can load the graphic: Bullet::graphic = load_bitmap(...); and to use this, use it like any other member data for member functions. I've only used static variables as public instance variables. I think you can handle private instance variables the same way, but don't quote me on that. Raul |