Cannot overload on constancy of this

Janice Caron caron800 at googlemail.com
Sun Dec 9 03:56:27 PST 2007


This won't compile:

    class A
    {
        int[] a;
        this() { a.length = 1; }

        int* ptr() { return a.ptr; }
        const const(int)* ptr() { return a.ptr; }
        invariant invariant(int)* ptr() { return a.ptr; }
    }

    void main()
    {
    	invariant A = cast(invariant)new A;
    }

The compile errors are:

main.d(8): function main.A.ptr conflicts with function main.A.ptr at main.d(7)
main.d(9): function main.A.ptr conflicts with function main.A.ptr at main.d(7)

The compiler appears to be telling me that const ptr() conflicts with
ptr(). Why?

This would be perfectly acceptable in C++. Why can't I say it in D?

Likewise, the compiler complains that invariant ptr() conflicts with
ptr(). Again I say: no it doesn't.



More information about the Digitalmars-d mailing list