Static class member Linker Errors

H

hyling.s1

Hi I'm getting "unresolved external symbol" linker errors from VC++
2003 when I use a static instance of a class for example

class myClass
{
protected:
static class2 mInstance; /* fails with "unresolved external symbol" */
static int mVar; /* works fine if I init it in the .cpp with: int
myClass:mVar = 0; */
}

What am I doing wrong?

Thanks
Hua-Ying
 
F

Frederick Gotham

posted:
Hi I'm getting "unresolved external symbol" linker errors from VC++
2003 when I use a static instance of a class for example

class myClass
{
protected:
static class2 mInstance; /* fails with "unresolved external symbol" */
static int mVar; /* works fine if I init it in the .cpp with: int
myClass:mVar = 0; */
}


class myClass {
protected:

class2 static mInstance; /* Just a declaration */
};

class2 myClass::mInstance( /* Arguments */ ); /* Definition */
 
V

Victor Bazarov

Hi I'm getting "unresolved external symbol" linker errors from VC++
2003 when I use a static instance of a class for example

class myClass
{
protected:
static class2 mInstance; /* fails with "unresolved external symbol" */
static int mVar; /* works fine if I init it in the .cpp with: int
myClass:mVar = 0; */
}

What am I doing wrong?

You're probably not defining your 'mInstance' anywhere. Read up on
static data members.

V
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top