Differences between "const Type function()" and "const(Type) function()"

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 22 05:22:24 PDT 2014


On Friday, 30 May 2014 at 12:57:52 UTC, anonymous wrote:
> It's not a cast. It's the unambiguous notation for a qualified
> type. Often you can omit the parentheses. With methods you
> cannot. With methods you need the parentheses to let the 
> compiler
> know that you indeed mean the return type to be const, not the
> method itself.

Please note that outside a class/struct, this notation :

      const T foo()

is meaningless, and before D 2.066 was silently ignored.

Now the compiler will notify you when the error occur, but you
still need to be extra-careful when using const with methods.


More information about the Digitalmars-d-learn mailing list