Mixins are not inherited?

Namespace rswhite4 at googlemail.com
Thu May 3 14:32:50 PDT 2012


By the following code i get these error messages:

----
Error: template RefTest.Ref.__unittest1.instanceof(T : Object,U : 
Object) cannot deduce template function from argument types 
!(A)(B)

Error: template RefTest.Ref.__unittest1.instanceof does not match 
any function template declaration
	
Error: template instance instanceof!(A) errors instantiating 
template	
----

How is this possible? I thougth that the mixin would be inherited 
and so every subclass would be implicit cast to his super type. 
Isn't that so?
If i write "mixin TRef!(B);" in class B, it works fine. Can 
anyone explain me why do i have to write it in class B?

[code]
unittest {
	bool instanceof(T : Object, U : Object)(const Ref!U obj) {
		const U o = obj.access;

		return const_cast(o).toString() == typeid(T).toString();
	}

	class A {
		mixin TRef!(A);
	}

	class B : A {
		//mixin TRef!(B);
	}

	class C : B {
		//mixin TRef!(C);
	}

	A a1 = new B();
	A a2 = new C();

	assert(instanceof!(A)(a1) == false);
	assert(instanceof!(B)(a1));
	assert(instanceof!(C)(a1) == false);

	writeln(a1);

	B b1 = cast(B) a1;

	assert(instanceof!(A)(b1) == false); // <-- fails

	writeln(b1);

	writeln();
}
[/code]

"TRef" is the same mixin template and "Ref" the same template 
struct as in my last threads.


More information about the Digitalmars-d-learn mailing list