🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Explicit constructors

Started by
0 comments, last by WitchLord 7 years, 4 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.

Advertisement

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