Skip to main content
gamedev.net
🔒 Locked

A static function pointer in a class

Started by The C modest god Feb 4, 2004 at 6:29 AM 6 replies 600+ views
Original Post
The C modest god
The C modest god
I have the following code: class ImageScaler { static void InitialScale (); static void (*pInitialScale)(); }; void ImageScaler::InitialScale () { ImageScaler:InitialScale(); } But I get the following errors for the last line: unresolved external symbol "private: static void (__cdecl* ImageScaler:InitialScale)(void)" (?pInitialScale@ImageScaler@@0P6AXXZA) Debug/V0P01.exe : fatal error LNK1120: 1 unresolved externals Why the compiler looks for a body of a function of the pointer to function member?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Sandman
Sandman
No, it's probably just looking for the instantiation, just like with any other static variable.

In your cpp file, outside of any functions, add:


void (*ImageScaler::pInitialScale)(void);


EDIT: Source tagged for smiley removal


[edited by - Sandman on February 4, 2004 7:39:14 AM]
The C modest god
The C modest god
quote:
Original post by Sandman
No, it''s probably just looking for the instantiation, just like with any other static variable.

In your cpp file, outside of any functions, add:


void (*ImageScaler::pInitialScale)(void);


EDIT: Source tagged for smiley removal


[edited by - Sandman on February 4, 2004 7:39:14 AM]


Now it works, but why did it need that?
I have a static DWORD member of a class and it doesnt require it to be instantiation?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
Sandman
Sandman
quote:
Original post by The C modest god
Now it works, but why did it need that?
I have a static DWORD member of a class and it doesnt require it to be instantiation?



It should do... all globals and static members need instantiating.

It may just be that you haven''t tried using it, so the linker hasn''t spotted it yet.
Qw3r7yU10p!
Qw3r7yU10p!
I''d already answered this in your other thread. This is sort of like cross posting. Glad you''ve got your answer but you didn''t respond to anything I posted which was getting you in the right direction.
The C modest god
The C modest god
Now the last thing I need to do is to use the static function pointer to point into a static function of a class, would that work?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower. Quote: Original post by Toolmaker Quote:
antareus
antareus
No, for that you need to use Boost''s Function library. A class member pointer only points to a member of a particular class instance, and a static class doesn''t have an instance.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Sandman
Sandman
quote:
Original post by antareus
No, for that you need to use Boost''s Function library. A class member pointer only points to a member of a particular class instance, and a static class doesn''t have an instance.


No, he can point it to a static member function without any problems at all.

If he tried to point it at a non-static member, then he might have problems, which could be solved either by rewriting the pointer definition (can''t remember the syntax off the top of my head) or by using a library like the Boost one you mention.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.