I got a problem with implicit value cast.
I register things like that :
template<class T>
class Param {
public:
Param(const T _value) : value_(_value), ref_count_(1) { };
T v() { return value_; } const
int add_ref() { return ++ref_count_; }
int release() { if( --ref_count_ == 0 ) { delete this; return 0; } return ref_count_;}
private:
T value_;
int ref_count_;
};
template<class T>
static Param<T> * Param_Factory(const double) {
return new Param<T>(double);
}
void myFunction(const double d) {
}
engine->RegisterObjectType("Pdouble", 0, asOBJ_REF);
engine->RegisterObjectBehaviour("Pdouble", asBEHAVE_FACTORY, "Pdouble @f(double)", asFUNCTIONPR(Param_Factory<double>, (), Param<double> *), asCALL_CDECL);
engine->RegisterObjectBehaviour("Pdouble", asBEHAVE_ADDREF, "void f()", asMETHOD(Param<double>, add_ref), asCALL_THISCALL);
engine->RegisterObjectBehaviour("Pdouble", asBEHAVE_RELEASE, "void f()", asMETHOD(Param<double>, release), asCALL_THISCALL);
engine->RegisterObjectBehaviour("Pdouble", asBEHAVE_IMPLICIT_VALUE_CAST, "double f() const", asMETHOD(Param<double>, v), asCALL_THISCALL);
engine->RegisterGlobalFunction("void myFunction(const double)", asFUNCTIONPR(myFunction, (const double), void), asCALL_CDECL);
if I do an implicit cast like this :
Pdouble myValue( 0.3 );
double temp = myValue; // <-- Implicit cast
myFunction( temp );
it works ok, but if I do an implicit cast in the function call like that :
Pdouble myValue( 0.3 );
myFunction( myValue ); // <-- Implicit cast
angelscript crashes with an illegal memory access.Is there anything wrong in my code or is implicit value cast not supposed to work when calling a function ?