Advertisement

Invalid static_cast registering Irrlicht class

Started by August 09, 2011 08:43 AM
3 comments, last by BrianEmpson 13 years, 3 months ago
Hello,

I am currently attempting to expose the Irrlicht engine to AngelScript. The first class I decided to implement was the 'dimension2d<T>' class.

Here is the line of code that is giving me problems:


u32 r;
//other registered functions snipped
r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asFUNCTIONPR(operator==, (const dimension2df&), bool),asCALL_CDECL_OBJFIRST);
assert(r >= 0);
//snipped


Here is the output my compiler gives upon trying to build said code:

E:\pb\main.cpp|291|error: invalid static_cast from type '<unresolved overloaded function type>' to type 'bool (*)(const irr::core::dimension2df&)'|

And finally, here is the actual code from the dimension2d<T> class:


bool operator==(const dimension2d<T>& other) const
{
return core::equals(Width, other.Width) &&
core::equals(Height, other.Height);
}


The whole source file:

http://irrlicht.sour..._8h_source.html

It appears to be complaining about the actual class itself, but I do not know why. Is there anyone out there who can point me in the right direction? If you need more information let me know.

Thank you.


u32 r;
//other registered functions snipped
r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asFUNCTIONPR(operator==, (const dimension2df&), bool),asCALL_CDECL_OBJFIRST);
assert(r >= 0);
//snipped


Here is the output my compiler gives upon trying to build said code:

E:\pb\main.cpp|291|error: invalid static_cast from type '<unresolved overloaded function type>' to type 'bool (*)(const irr::core::dimension2df&)'|


Usually there is more than one operator== and if you try to pass the function itself the compiler can't figure out which one you mean. Usually that is inferred from the context of the call to operator== but since you are only passing the function/method to something and are not calling it, there are no arguments to infer the types from... you probably have to pass "dimension2d<float>::operator==" or something like that instead.
Advertisement
Hmm...it doesn't appear to be the operator= parameter that is failing the compile check...I tried what you suggested, but the same error occurs. Maybe it is something with the field next to the operator= statement? I can't figure out what though. I wish I could just say "Here is the class, let the script access it." If only it were that easy...
operator== in this case is a member function, so you should use asMETHODPR rather than asFUNCTIONPR. It's also const, which you need to take into account, and you should use asCALL_THISCALL. You may want to read this documentation page.

operator== in this case is a member function, so you should use asMETHODPR rather than asFUNCTIONPR. It's also const, which you need to take into account, and you should use asCALL_THISCALL. You may want to read this documentation page.


SiCrane, yes that worked beautifully. I read that documentation page before, I just never realized that I would have to use a different declaration parameter (METHODPR). Here is the correct code I used:

r = engine->RegisterObjectMethod("dimension2f", "bool opEquals(const dimension2f &in) const", asMETHODPR(dimension2df, operator==, (const dimension2df&) const, bool),asCALL_THISCALL); assert(r >= 0);

This topic is closed to new replies.

Advertisement