Jump to content
  • Advertisement
Sign in to follow this  
kunitoki

how to call inner classes constructors (with arguments) ?

This topic is 4477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 !

Share this post


Link to post
Share on other sites
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;
};

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!