Skip to main content
GameDev.net gamedev.net
🔒 Locked

Function Pointers

Started by masonium Oct 14, 2001 at 2:14 AM 3 replies 400+ views
Original Post
masonium
masonium
How do you specify whether your function is __thiscall or __cdcel? When I try to compile this:
  
...
// setup type of interpolation

md2Vector (* Interpolate) (md2Vector, md2Vector);

if (animType == MD2_LINEAR)
	Interpolate = LinearInterpol;
if (animType == MD2_CUBIC)
	Interpolate = CubicInterpol;
...
  
I get these errors: C:\My Documents\Mason''s Files\Programming\OpenGL\Test\MD2Model.cpp(234) : error C2440: ''='' : cannot convert from ''class vector3D (__thiscall MD2Model::*)(class vector3D,class vector3D)'' to ''class vector3D (__cdecl *)(class vector3D,class vector3D)'' There is no context in which this conversion is possible C:\My Documents\Mason''s Files\Programming\OpenGL\Test\MD2Model.cpp(236) : error C2440: ''='' : cannot convert from ''class vector3D (__thiscall MD2Model::*)(class vector3D,class vector3D)'' to ''class vector3D (__cdecl *)(class vector3D,class vector3D)'' There is no context in which this conversion is possible This code snippet is in the member function of a class. LinearInterpol and CubicInterpol are member functions of the same class. Also, md2Vector is just a typedef''d vector3D.
Oluseyi
Oluseyi
__thiscall is not a keyword, so you can''t explicitly declare your function to employ its conventions. However, static class member functions are __thiscall.

You''re trying to resolve a function that is callable from outside the class as a member function. You therefore need that member function to have the same behaviors as a global function - you make it static. You''ll also have to make you function pointer static (remember to initialize it at class scope).
Dactylos
Dactylos
To make function pointers to member-functions (methods), write e.g:

md2Vector (MD2Model::* Interpolate) (md2Vector, md2Vector);
Dactylos
Dactylos
quote:
Original post by Oluseyi
__thiscall is not a keyword, so you can''t explicitly declare your function to employ its conventions. However, static class member functions are __thiscall.


IIRC static member functions are __stdcall. __thiscall implies that a hidden parameter is passed (this), since static member functions don''t have a hidden parameter, they aren''t called with the __thiscall convention.

Oluseyi
Oluseyi
Oops!

Yep, that''s it. Member functions are __thiscall because they push the this pointer onto the stack (which is how the code is able to access the appropriate member variables, etc), while static functions are __stdcall (as are WIN32 API functions).

Thanks for the heads up, Dactylos!

Topic Locked

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

Sign in to reply to this topic.