[Issue 3282] The overload and override issue of const/immutable member functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 30 23:34:40 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=3282



--- Comment #3 from Haruki Shigemori <rayerd.wiz at gmail.com> 2010-01-30 23:34:40 PST ---
This problem's characteristics changed at dmd2.040.

import std.stdio;
class Base
{
    string f()
    {
        return "Base.f()";
    }
}
class Derived : Base
{
    string f()
    {
        return "Derived.f()";
    }
    string f() immutable
    {
        return "Derived.f() immutable";
    }
    string f() shared
    {
        return "Derived.f() shared";
    }
}
void main()
{
    auto x = new Base;
    writeln(x.f());
    auto y = new Derived;
    writeln(y.f());
    auto z = new immutable(Derived);
        //main.d(15): Error: function main.Derived.f of type immutable string()
overrides but is not covariant with main.Base.f of type string()
    writeln(z.f());
    auto w = new shared(Derived);
        //main.d(19): Error: function main.Derived.f of type shared string()
overrides but is not covariant with main.Base.f of type string()
    writeln(w.f());
}

Are both errors correctly?
I expected that z.f() calls "Derived.f() immutable" and w.f() calls
"Derived.f() shared".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list