M
mongoose7
Hello everyone.
I wrote a small class to keep some global variables updated. I use a
static method to get the single instance of this class in 2 places in
the code. In one place the global variable is being incremented in the
other it stays at zero...
I dont understand whats going wrong sice the same instance is being
called through the getInstance method... (i think ). Its as if a new
object is being created every time in the second place where im calling
the methods. Any ideas?
Code below.
Thanks!!!
Mongoose7
class CDynamicGlobal
{
public:
// The CDynamicGlobal is treated as a single object using the
// singleton design pattern
static CDynamicGlobal& getInstance()
{
static CDynamicGlobal pInstance;
return pInstance;
}
// Increment the Frame counter
void incFrameNumber();
// Get the current frame number
long getFrameNumber();
// Initialize all the counters
void init();
private:
long __frameNumber;
CDynamicGlobal();
};
I wrote a small class to keep some global variables updated. I use a
static method to get the single instance of this class in 2 places in
the code. In one place the global variable is being incremented in the
other it stays at zero...
I dont understand whats going wrong sice the same instance is being
called through the getInstance method... (i think ). Its as if a new
object is being created every time in the second place where im calling
the methods. Any ideas?
Code below.
Thanks!!!
Mongoose7
class CDynamicGlobal
{
public:
// The CDynamicGlobal is treated as a single object using the
// singleton design pattern
static CDynamicGlobal& getInstance()
{
static CDynamicGlobal pInstance;
return pInstance;
}
// Increment the Frame counter
void incFrameNumber();
// Get the current frame number
long getFrameNumber();
// Initialize all the counters
void init();
private:
long __frameNumber;
CDynamicGlobal();
};