🎉 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!

Value type with no default constructor?

Started by
2 comments, last by WitchLord 9 years, 6 months ago

I'm trying to register a value type that doesn't have a default constructor,

but the script engine complains:

E: : (0, 0): Type 'Type' is missing behaviours
I: : (0, 0): A non-pod value type must have the default constructor and destructor behaviours

The problem is that I don't want to enable users to create instances of my class without parameters, because it doesn't make any sense, and would need many unneeded checks in C++...

Advertisement
At the moment AngelScript doesn't support value types that cannot be constructed without arguments. I'll see if I can implement this support for a future release.

For now, I suggest you register the default constructor with an implementation to a known state, e.g.


void defaultconstruct_Type(void *mem)
{
  new(mem) Type(0); // Call the non-default constructor to initialize the object to a known state.
}

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

That's what I do at the moment, so I check in every function if the referenced type is not null before doing anything.

I hope this feature to be available one day :)

I'll see what I can do. smile.png

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