Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unresolved External Error when using static member variables... help?

Status
Not open for further replies.

nexius

Programmer
Jul 8, 2000
109
CA
Hi.

I want to construct a class with static member variables and static member functions but the compiler keeps giving me "Unresolved External Error"'s!

I know that when you declare a variable as static outside a class it is only accessible within the file it was declared in... and this would give the UE errors, but not in a class... so why then?

Please help. Thanks in advance.
 
When you declare a static member variable in a class, you also have to allocate storage for it as follows:

class Foo
{
private:

static int i;

};

int Foo::i;

The fact that you haven't allocated storage will give the 'Unresolved External' error.

Temps
 
Alright great, thanks, that helps alot.

However, now I've got another problem. I can't include the class in other files without getting more linking errors.

It says that all my static variables and functions are already declared in another *.obj file...

error LNK2005...

I don't know how else to do it.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top