Colobot Wiki

Instruction new (for specialists)[]

The new operator creates a class instance:

	MyClass item;    // now item is a null reference
	item = new MyClass(); // now item is a reference
	                      // to a new class instance

If you want to create a new instance at declaration time you can omit the new new operator by putting () after the declaration:

Instead of:

	MyClass item = new MyClass();

you can write:

	MyClass item();

If your class has a constructor with parameters you can write:

	MyClass item = new MyClass(2, 3);


	MyClass item(2, 3);