immutable method not callable using argument types () - doesn't make sense

Steven Schveighoffer schveiguy at yahoo.com
Tue Mar 27 04:34:50 PDT 2012


On Tue, 27 Mar 2012 04:49:57 -0400, Daniel Donnelly <enjoysmath at gmail.com>  
wrote:

> The two solutions are:
>
> inout(A) dup() inout { ... }

This transfers the constancy from the object to the result.  Is that what  
you want?  For arrays, dup means "return mutable", no matter what  
constancy it is called on.

> I'm using the latter.  Basically all I need is to copy any object:  
> const, immut-, or mutable.

BTW, here is what the compiler is complaining about:

immutable B dup();

This is a member function, with the attribute immutable.  What this does  
is specify that the hidden 'this' pointer is immutable.  It's equivalent  
to this:

B dup(immutable(B) this);

So what the compiler is saying is that you can't call dup with arguments  
(), you must call it with arguments '() immutable', meaning you must call  
it on an immutable B, not a mutable B.

-Steve


More information about the Digitalmars-d mailing list