Link error for a static member

N

NewToCPP

typedef int (*ActionFunction) ();

class FunctionInterface
{
static ActionFunction actionFn[3][2];

public:
static void init();
static void initActionFunctions();
static action_process1();
static action_process2();
};




void FunctionInterface::initActionFunctions()
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 2; ++j)
{
actionFn[j] = 0;
}
}
actionFn[1][1] = FunctionInterface::action_process1;
actionFn[2][2] = FunctionInterface::action_process2;
}

......................

.......................


When I build this I got the following error

MyProgram error LNK2001: unresolved external symbol "private: static
int (__cdecl*(* FunctionInterface::actionFn)[2])(void)"
(?actionFn@FunctionInterface@@0PAY01P6AHXZA)


Can any one help me in this. I cant figure out why it has problem.

Thanks.
 
V

Victor Bazarov

NewToCPP said:
[...]
When I build this I got the following error

MyProgram error LNK2001: unresolved external symbol "private: static
int (__cdecl*(* FunctionInterface::actionFn)[2])(void)"
(?actionFn@FunctionInterface@@0PAY01P6AHXZA)


Can any one help me in this. I cant figure out why it has problem.

Doesn't your favourite C++ book tell you that all static data members
should be _defined_ (in addition to the declaration in the class)?

V
 
D

David Harmon

On 27 Oct 2006 14:09:27 -0700 in comp.lang.c++, "NewToCPP"
When I build this I got the following error

MyProgram error LNK2001: unresolved external symbol "private: static
int (__cdecl*(* FunctionInterface::actionFn)[2])(void)"
(?actionFn@FunctionInterface@@0PAY01P6AHXZA)

This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[10.11] Why are classes with static data members getting linker
errors?" It is always good to check the FAQ before posting. You
can read the FAQ at:
http://www.parashift.com/c++-faq-lite/
 
J

Jacek Dziedzic

NewToCPP said:
typedef int (*ActionFunction) ();

class FunctionInterface
{
static ActionFunction actionFn[3][2];

public:
static void init();
static void initActionFunctions();
static action_process1();
static action_process2();
};




void FunctionInterface::initActionFunctions()
{
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 2; ++j)
{
actionFn[j] = 0;
}
}
actionFn[1][1] = FunctionInterface::action_process1;
actionFn[2][2] = FunctionInterface::action_process2;
}

.....................

......................


When I build this I got the following error

MyProgram error LNK2001: unresolved external symbol "private: static
int (__cdecl*(* FunctionInterface::actionFn)[2])(void)"
(?actionFn@FunctionInterface@@0PAY01P6AHXZA)


Can any one help me in this. I cant figure out why it has problem.


Why not read the FAQ?

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.11

HTH,
- J.
 

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,795
Messages
2,569,644
Members
45,358
Latest member
TreyTritt8

Latest Threads

Top