|Original post by WitchLord|
The 'new' operator will work like it does in C++. It will allocate an object and return it already initialized. Object a = new Object();
Fair enoiugh about the reference thingy, but I'm still confused about the need for the 'new' operator. To declare a primative, such as an int, I just do this:
But, if I want to create a custom object, I have to do this:
SomeClass myClass = new SomeClass();
I'm not sure why I need to do this though! What is the purpose of the 'new' operator? Surley it would be nicer to do this:
SomeClass myClass(); //Create an object
SomeCladd myClass; //Same as the above, the default constructor is called
The point I'm trying to make is I'm not sure angelscript needs the operator 'new', as everything you create will infact be a smart pointer, why complicate things. Perhaps I'm missing something, but I don't like the way in C# you have to use new unless it's a primative or struct (in C# there is a difference between classes and structs), but if it is a struct, you can still use new if you want. Since C# has garbage collection (AS kinda does, as the scri[pt takes care of all the memory), I've never really understood the need to declare somethings with new, but otherthings don't need it.
I hope that makes sense, my question is basically why do we need operator 'new'?
Thanks for your time.