Sign in to follow this  
BrianEmpson

Invalid static_cast registering Irrlicht class

Recommended Posts

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:

[code]
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
[/code]

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:

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

The whole source file:

[url="http://irrlicht.sourceforge.net/docu/dimension2d_8h_source.html"]http://irrlicht.sour..._8h_source.html[/url]

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.

Share this post


Link to post
Share on other sites
[quote name='brianempson' timestamp='1312879408' post='4846588']
[code]
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
[/code]

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&)'|

[/quote]
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.

Share this post


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

Share this post


Link to post
Share on other sites
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 [url=http://www.angelcode.com/angelscript/sdk/docs/manual/doc_register_func.html] this documentation page[/url].

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1312890169' post='4846638']
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 [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_register_func.html"] this documentation page[/url].
[/quote]

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:

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this