|
-
May 8th, 2009, 06:40 AM
#1
member static function pointers
when i call a member static function pointer which is initialized in constructor. it gives me unresolved external linking error.
any ideas?
thanks already
-
May 8th, 2009, 08:01 AM
#2
Re: member static function pointers
Static members cannot be initialized inside the class (save the few exceptions).
Meaning, it can only be initialized at definition(allocation).
Move your statement outside the class body.
-
May 8th, 2009, 08:09 AM
#3
Re: member static function pointers
let me give an example;
//class.h
class a
{
public :
a();
static int x;
static int (*y)(int z);
};
//class.cpp
int a::x = 0; /*this lets me to use x from everywhere*/
int (a::*y) = 0; /*when i try to reach y. now it gives unresolved external error*/
maybe i just need syntax to set function pointer some value.
Last edited by phenixa; May 8th, 2009 at 08:11 AM.
-
May 8th, 2009, 08:20 AM
#4
Re: member static function pointers
Honestly I find function pointer syntax to be a pain and unintuitive....so whenever I need to use one, the first thing I do is typedef it. Once you do that then the definition would look like
Code:
MyFunPtr a::myPtr = NULL;
-
May 8th, 2009, 08:27 AM
#5
Re: member static function pointers
 Originally Posted by phenixa
let me give an example;
//class.h
class a
{
public :
a(){}
static int x;
static int (*y)(int z);
};
//class.cpp
int a::x = 0; /*this lets me to use x from everywhere*/
int (a::*y) = 0; /*when i try to reach y. now it gives unresolved external error*/
maybe i just need syntax to set function pointer some value.
Ah, you said you initialized it in the class constructor! did you not!!
And Lindley is right. Using typedef is much easier~
-
May 8th, 2009, 08:28 AM
#6
Re: member static function pointers
thank you very much lindley
-
May 8th, 2009, 08:32 AM
#7
Re: member static function pointers
 Originally Posted by phenixa
thank you very much lindley
Just for the record, the problem was the class, not your syntax.
And you're welcome.
-
May 8th, 2009, 08:32 AM
#8
Re: member static function pointers
 Originally Posted by potatoCode
Ah, you said you initialized it in the class constructor! did you not!!
And Lindley is right. Using typedef is much easier~
i meant that yeah
like this
//class.cpp
a::a()
{
y = some function address;
}
thanks for helping
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|