Typedef of class doesn't work?

Bradley Smith digitalmars-com at baysmith.com
Sun Jan 14 16:21:10 PST 2007


import std.stdio;

class A {
   this(float v) { value = v; }
   float getValue() { return value; }
	
private:
   float value;
}

typedef A B;

void main() {
   B b = new B(1);
   writefln(b.value);
}

The above code produces the following errors:
 >dmd testTypedef.d
testTypedef.d(14): Error: cannot implicitly convert expression (new 
B(1F)) of type testTypedef.A to B
testTypedef.d(15): Error: this for value needs to be type A not type B

Aliasing works for classes, but not typedef. Why not?

Thanks,
   Bradley


More information about the Digitalmars-d-learn mailing list