Skip to main content
gamedev.net
🔒 Locked

static members

Started by frogant Apr 18, 2001 at 4:28 AM 7 replies 350+ views
Original Post
frogant
frogant
hi, I get this linker error when I try to use static data members in c++ classes: unresolved external symbol "public: static int NNTank::m_reference_count" (m_reference_count@NNTank@@2HA) using vc++ 5 pro sp3 what gives?
"the many sings to us"
jwalker
jwalker
put this in your cpp file ...

static int NNTank::m_reference_count = 0;


should solve the linker problem ..

Edited by - jwalker on April 18, 2001 10:09:10 AM
Clash Rocker
Clash Rocker
I though you had to leave out the "static" in the definition?
.H
    
class foo
{
public:
static int bar();
private:
static int spoot;
};


.CPP

int foo::bar()
{
//...

}





Edited by - Clash Rocker on April 18, 2001 7:02:32 AM
capn_midnight
capn_midnight
Nope, you use the static each time.

Are you even trying to be intelligent?
''cuz if you are, it ain''t workin''
Down with Tiberia!
arunvb
arunvb
I am not sure about other compiler but in VC++, you certainly DONT need to include the static in your definition. It is enough if we mention it in out declaration.

I have a few static variables in my project, where I have the keyword static in the declaration alone. I dont use the keyword static in my definitions. It works perfectly for me.

Thanks
Arun
Clash Rocker
Clash Rocker
Well I got around to trying it out on gpp. And it compiled
with zero errors when I left out that static on the function
definition.
null_pointer
null_pointer
You should not use static in the definition, because that use of static has nothing to do with static data members. This is the correct way to do it:


// in the header file:
class someclass
{
public:
static int data;
};

// in the source file:
int someclass::data;

merlin9x9
merlin9x9
Right, and it''s the same with other keywords such as virtual and inline.
frogant
frogant
thanks for all the replies. I got what I needed +.
"the many sings to us"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.