Jump to content
  • Advertisement

Archived

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

AcidInjury

Class Instance count

This topic is 5465 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!