linking error on assiging function pointer to static member

This code gives me linking error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void func1()
{
  cout<<"func1()"<<endl;
}

class a
{
  public:
  static void (*func)(void);
};

int _tmain(int argc, _TCHAR* argv[])
{
  a::func = func1;
  a A;
  A.func();  
}


The linking error says this:
test.obj : error LNK2001: unresolved external symbol "public: static void (__cdecl* a::func)(void)" (?func@a@@2P6AXXZA)
1>C:\Users\petar.HQ\Documents\Visual Studio 2008\Projects\test\Debug\test.exe : fatal error LNK1120: 1 unresolved externals

ANNOTATION: What I'm trying is to assign static member pointer to any function's address (of static member or global function) from the same type;

Any sugestions why it gives such error?
Thanx
Last edited on
Hi dude, this is the god damn solution to your problem (the line in bold letters):

void func1()
{
cout<<"func1()"<<endl;
}

class a
{
public:
static void (*func)(void);
};

void (*a::func)(void);

int _tmain(int argc, _TCHAR* argv[])
{
a::func = func1;
a A;
A.func();
}

P.S. Sorry I found myself the answer. Thanks anyway. See you soon again.
Topic archived. No new replies allowed.