www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cannot overload on constancy of this

reply "Janice Caron" <caron800 googlemail.com> writes:
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.
Dec 09 2007
next sibling parent Walter Bright <newshound1 digitalmars.com> writes:
Janice Caron wrote:
 This won't compile:

It's a bug. I'll take care of it.
Dec 09 2007
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
On 12/9/07, Walter Bright <newshound1 digitalmars.com> wrote:
 It's a bug. I'll take care of it.

Cool! Thank you, that's brilliant!
Dec 09 2007