override and package
Namespace
rswhite4 at googlemail.com
Thu Sep 12 02:28:50 PDT 2013
Code:
----
import std.stdio;
class T1 {
protected:
void _apply() {
writeln("Call T1");
}
}
class T2 : T1 {
public:
override void _apply() {
writeln("Call T2");
}
}
class T3 : T1 {
protected:
override void _apply() {
writeln("Call T3");
}
}
class T4 : T1 {
package:
void _apply() { /// <-- [1]
writeln("Call T4");
}
}
void main()
{
T1 t1 = new T1();
T2 t2 = new T2();
T3 t3 = new T3();
T4 t4 = new T4();
t1._apply();
t2._apply();
t3._apply();
t4._apply();
}
----
Produce the correct output:
Call T1
Call T2
Call T3
Call T4
If I remove 'override' from T3 (or also T2) I get the correct
deprecation message:
/d172/f194.d(19): Deprecation: overriding base class function
without using override attribute is deprecated (f194.T3._apply
overrides f194.T1._apply)
But if I try to write 'override' before [1], I get this error
message:
Error: function T4._apply cannot override a non-virtual function
This seems inconsistent. I really overwrite the method, and then
I put it in a package label.
More information about the Digitalmars-d-learn
mailing list