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

how to call inner classes constructors (with arguments) ?

Started by
4 comments, last by WitchLord 18 years, 2 months ago
i'm trying to get the best out of the new features of 2.6.0, especially when relating with the classes. i have to declare a class member which is actually another class (c++ or script class doesn't matter). this member have only a class constructor that takes arguments, and i don't know how to call the constructor: <angelscript> class ScriptComponent { ScriptComponent(const String& obj) { // how to call constructor for this.self ? } RealComponent self; }; </angelscript> now... RealComponent constructor takes two arguments... how to correctly initialize it, since it cannot have assignment operator registered (and so "this.self = createRealComponent();" cannot be called) ? i've tried doing a "this.self(arguments);" in MyComponent constructor but no way... any thoughts about this ?
Advertisement
In C++, the only way to have members who do not have default constructors is to use the initializer list. In C++;

class Foo{   Bar m_bar;public:   Foo() : m_bar(parameters) {}};


I don't think Angelscript supports this, and thus theres no way to do it yet.
yeah man, thanx you... c++ is fine here ;)
i think that a lot of features for class support have to be done in angelscript before thinking about inheritance and such...

anyway... happy easter !
Indeed, this hasn't been implemented yet.

Would it be possible for you to use a two-step initialization for the class? I.e:

class ScriptComponent {   ScriptComponent(const String& obj)   {     // self is initialized with default constructor,     // now call the init function to initialize the rest.    self.init();  }   RealComponent self; };

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

yeah for sure is possible. i've already done that way. but i asked for clarify myself of this lackness. i prefer have a clear way of doing things and i think when relating with classes, every part of the problem should be addressed.
i think that not having different than default constructor in classes isn't a gr8 miss, but indeed, is somelike a base part of a language (script or not), a perfect logical block when dealing with classes: why i have to duplicate the constructors with functions that do the same things ? in some cases i can use constructors and in other i should use initFunctions, that practically mimics the first...
I agree with you, and AngelScript will definitely support the use of non-default constructors for class members as well. I just haven't gotten that far yet. :)

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