Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

masonium

Function Pointers

This topic is 6124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
__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).

Share this post


Link to post
Share on other sites
To make function pointers to member-functions (methods), write e.g:

md2Vector (MD2Model::* Interpolate) (md2Vector, md2Vector);

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!