Class Instance count

Started by
1 comment, last by AcidInjury 20 years, 8 months ago
As a fair warning, I''m new to Object Oriented programming for C++. I was wondering if there was a way for Objects of the same class to share information about each other. Specifically I have a graphics class for OpenGL. It has a private member hDC and hRC, obviously holding Device and Rendering Contexts. I want X ammount of instances of this class to share display-list space (using wglShareList). Is there an elegant way to handle this inside the class, or should I make it up to the calling program to keep track of the ammount of instances, and *manually* share the list-space? Thanks, Will Reynard
Advertisement
static member variables are ideal for this. Check ''em out in your C++ book.

How appropriate. You fight like a cow.
Just declare something as static if you want it shared between all instances of a class.

EG:

class myclass{public:   myclass();            void DoSomething();private:   static int NumOfMyclasses;};myclass::myclass()     //constructor{NumOfMyclasses++;}void myclass::DoSomething(){//do stuff}



Hope that helps,

-J

EDIT: someone beat me to it.


[edited by - jason2jason on August 5, 2003 12:52:07 PM]

This topic is closed to new replies.

Advertisement