static data member

S

Steve

I am experiencing the following:
I am using a static member variable of a class to track how many instances
of a class are in existence using MSVC 6 SP5. Access error occurs when I
try to run. I try to debug, but anytime that a function in this class is
called it vectors to an address in another loaded module. Say, I try to set
a breakpoint on the statement in the constructor. As soon as the debugger
tries to jump to the constructor, it instead jumps into an unknown spot in
another loaded variable. Compiler or debugger problem maybe? Any guesses or
workarounds? Thanks. Steve

SomeClass.h:

class SomeClass
{
private:
static USHORT m_ushCount;
};

And define \ initialize \ use it at file scope like this:

SomeClass.cpp:

USHORT SomeClass::m_ushCount = 0;

SomeClass::SomeClass()
{
m_ushCount++;
}

SomeClass::~SomeClass()
{
m_ushCount--;

if(m_ushCount == 0)
{
//delete some support stuff when there are no more instances of this
class
}
}
 
B

Bob Hairgrove

I am experiencing the following:
I am using a static member variable of a class to track how many instances
of a class are in existence using MSVC 6 SP5. Access error occurs when I
try to run. I try to debug, but anytime that a function in this class is
called it vectors to an address in another loaded module. Say, I try to set
a breakpoint on the statement in the constructor. As soon as the debugger
tries to jump to the constructor, it instead jumps into an unknown spot in
another loaded variable. Compiler or debugger problem maybe? Any guesses or
workarounds? Thanks. Steve

It sounds like you have an old .lib file somewhere in your project
which is out of synch with the declarations in the headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top