🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Overloaded functions

Started by
2 comments, last by Jimfing 19 years, 2 months ago
I would search for this but the GD.net search feature is still broken :( How are overloaded C++ functions supposed to be handled when using RegisterObjectMethod? Currently I get the compile error:

error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'void (__thiscall CRenderer::* )(void)'
Thanks for any help.
Advertisement
You register a wrapper for the function, and register the wrappers as far as i know. I've thought about how it would be nice to be able to get the address of an overloaded function but i do not know how.


static double FloatIPow(float x, int y){	return pow(x, y);}static double FloatFPow(float x, float y){	return pow(x, y);}static double DoubleIPow(double x, int y){	return pow(x, y);}static double DoubleDPow(double x, double y){	return pow(x, y);}
You need to use the macro asFUNCTIONPR(func, paramlist, rettype) or asMETHODPR(class, method, paramlist, rettype). For example:

void print(float);void print(string&);void print(int);engine->RegisterGlobalFunction("void print(float)", asFUNCTIONPR(print,(float),void), asCALL_CDECL);engine->RegisterGlobalFunction("void print(string∈)", asFUNCTIONPR(print,(string&),void), asCALL_CDECL);engine->RegisterGlobalFunction("void print(int)", asFUNCTIONPR(print,(int),void), asCALL_CDECL);


What the macro does is that it tells C++ exactly what overloaded function you wish to take the address of. It expands to:

asFUNCTIONPR(print, (string&), void) => (void (*)(string&))print

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

That's perfect! Thanks!

You do a great job! :)

This topic is closed to new replies.

Advertisement