Advertisement

Explicit constructors

Started by February 08, 2017 04:14 PM
0 comments, last by WitchLord 7 years, 9 months ago

It is currently possible to implicitly invoke the constructor of one type to call the constructor of another:


engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(int value)", asFUNCTION(String_IntConstruct), asCALL_CDECL_OBJLAST);

engine->RegisterObjectBehaviour("string_t", asBEHAVE_CONSTRUCT, "void f(const string& in str)", asFUNCTION(string_t_StrConstruct), asCALL_CDECL_OBJLAST);

string_t str = 0; //Becomes "0"

This is allowed due to implicit constructor usage. Is there any way to make the string constructor explicit so only string( 0 ) will be considered valid, like C++'s explicit constructor syntax?

I don't see any way to specify this for value or reference types at this time.

Currently no.

However it is something I plan to add support for in a future release. (I thought I had it documented in my to-do list already, but apparently I had forgotten to).

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

This topic is closed to new replies.

Advertisement