digitalmars.D.bugs - typedef-ed ctor
- typedef d.com (28/28) May 09 2005 Suppose a class has ctor defined, then a typedef-ed class cannot use tha...
- Thomas Kuehne (15/42) May 11 2005 -----BEGIN PGP SIGNED MESSAGE-----
Suppose a class has ctor defined, then a typedef-ed class cannot use that ctor: ------------------------------------------------------------ class A { public this(int param) {} } typedef A B; #void foo() { # A a = new A(0); // OK # B b = new B(0); // error: cannot implicitly convert expression # // (new A (0)) of type typedef.A to B #} ------------------------------------------------------------ by contrast, if no ctor defined in A, then it works: ------------------------------------------------------------ class A {} typedef A B; void foo() { A a = new A(); //OK B b = new B(); //OK } ------------------------------------------------------------
May 09 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 typedef d.com schrieb am Tue, 10 May 2005 02:00:09 +0000 (UTC):Suppose a class has ctor defined, then a typedef-ed class cannot use that ctor: ------------------------------------------------------------ class A { public this(int param) {} } typedef A B; #void foo() { # A a = new A(0); // OK # B b = new B(0); // error: cannot implicitly convert expression # // (new A (0)) of type typedef.A to B #} ------------------------------------------------------------ by contrast, if no ctor defined in A, then it works: ------------------------------------------------------------ class A {} typedef A B; void foo() { A a = new A(); //OK B b = new B(); //OK } ------------------------------------------------------------This is illegal code: http://digitalmars.com/d/class.html#constructors # If there is no constructor for a class, but there is a constructor for # the base class, a default constructor of the form: # this() { } # # is implicitly generated. Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCgr903w+/yD4P9tIRAmD/AKDIMkyX2t4vBwebTvtYjGmEcfdLDACcCUxV Z58F8YAyPXK17lDQxlEtVXg= =l/k8 -----END PGP SIGNATURE-----
May 11 2005