class constructor

Nicolas Guillemot nlguillemot at gmail.com
Sat Apr 13 00:57:28 PDT 2013


Classes are instanciated with new, structs are not. The following 
program compiles:

class A {
	int myVal;

	this(int val) {
		myVal = val;
	}
}

struct B {
	int myVal;

	this(int val) {
		myVal = val;
	}
}

void main() {
	A myA = new A(8);

	B myB = 8;
}


More information about the Digitalmars-d-learn mailing list