asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true

Started by
3 comments, last by FDsagizi 11 years ago

Hi Andreas smile.png

with asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT we can create all objects from c++ code, for deserealization - It work fine!

but, for scripts, i think no need use this.

exemple:

this code work, but it's not goood


class SomeClass{
     SomeClass( int init_param ){}
}
void f(){
     SomeClass s;
}
 

Advertisement
The flag asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT is to tell the compiler to implement the default constructor even though the class has a defined non-default constructor. This is mostly used for backwards compatibility as it was the behaviour in the compiler before version 2.22.1. When deserializing objects you should use the method CreateUninitializedScriptObject() to get the object and then fill out all the members explicitly.

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

yes you are absolutely right!
CreateUninitializedScriptObject work from c++ - and this good, but def counstructor we can use from script - it's not good!
I want to even when the flag is set, it shows an error - not defined a default constructor( only from script ).
ex:


// asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, false
class SomeClass{
     SomeClass( int init_param ){}
}
void f(){
     SomeClass s; // No default constructor for object of type 'SomeClass'.
}

//-----------------------------------------------------------------------------

//next 
// asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT, true ( current time )
class SomeClass{
     SomeClass( int init_param ){}
}
void f(){
     SomeClass s; // work
}

//-----------------------------------------------------------------------------

// a want to, we set asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT true, and we have - 
class SomeClass{
     SomeClass( int init_param ){}
}
void f(){
     SomeClass s; // No default constructor for object of type 'SomeClass'.
}
// add constructor
class SomeClass{
     SomeClass(){  /* def constructor */ }      
     SomeClass( int init_param ){}
}
void f(){
     SomeClass s; // work
}

No. Since you don't want the default constructor to be available automatically, then you should _not_ set the flag asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT to true.

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

No. Since you don't want the default constructor to be available automatically, then you should _not_ set the flag asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT to true.

oh yes, im sorry!rolleyes.gif

i thinking CreateUninitializedScriptObject work only with asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT to true.

cool!smile.png

This topic is closed to new replies.

Advertisement