Archived

This topic is now archived and is closed to further replies.

AcidInjury

Class Instance count

Recommended Posts

AcidInjury    122
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

Share this post


Link to post
Share on other sites
Sneftel    1788
static member variables are ideal for this. Check ''em out in your C++ book.


How appropriate. You fight like a cow.

Share this post


Link to post
Share on other sites
Jason2Jason    166
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]

Share this post


Link to post
Share on other sites