Hi,
I've got a lot of shared_ptr underneath my script objects and because of the new features of 2.29.2 I wanted to try registering the handy "operator bool" that allow testing shared_ptr like this :
if( myShared ){
}
For some reason I can't make opConv or opImplConv to work for booleans. To make sure I wasn't doing something stupid on the c++ side, I tried doing the same in the script using the code provided in the documentation but without success.
It is an extremely useful feature of shared_ptr in c++ and I'd love to be able to expose the same feature for the classes I register to angelscript.
Here's what I tried in c++ :
engine->RegisterObjectMethod( "ObjectRef", "bool opImplConv() const", asMETHODPR(ObjectRef, operator bool, () const, bool ), asCALL_THISCALL );
and in Angelscript:
class MyObj
{
double myValue;
double opImplConv() const { return myValue; }
bool opImplConv() const { return myValue > 0; }
// bool opConv() const { return myValue > 0; }
};
MyObj c;
c.myValue = 0.12345;
double cDouble = c; // this works
bool cBool = c; // this doesn't and gives "MainSection (66, 16) : ERR : Can't implicitly convert from 'MyObj&' to 'bool'."
Is this a limitation of the new conversion operator or am I missing something obvious?
Thanks in advance!
Simon.