Re: Differences between const Type function() and const(Type) function()

2014-08-22 Thread via Digitalmars-d-learn
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

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

2014-05-30 Thread francesco cattoglio via Digitalmars-d-learn
Today I got the following compile error: Cannot implicitly convert expression (blabla) of type const(Type) to Type and this is a reduced example ( also on http://dpaste.dzfl.pl/f2f3bd921989): module test; import std.stdio; class Foo { int i = 42; } class MyClass {

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread bearophile via Digitalmars-d-learn
francesco cattoglio: And why is const(Foo) getQ so much different? (e.g: this is an explicit cast, right? In D the syntax for casts is cast(something)somethingElse. Bye, bearophile

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread anonymous via Digitalmars-d-learn
On Friday, 30 May 2014 at 12:35:46 UTC, francesco cattoglio wrote: class MyClass { [...] const (Foo) getQ () const { return _Q; } // OK // const Foo getQ () const { return _Q; } // fails } [...] I don't really understand what's going on here. Why is const Foo getQ() wrong?

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread francesco cattoglio via Digitalmars-d-learn
On Friday, 30 May 2014 at 12:57:52 UTC, anonymous wrote: And why is const(Foo) getQ so much different? (e.g: this is an explicit cast, right? Is there anything that might go wrong?) It's not a cast. It's the unambiguous notation for a qualified type. Often you can omit the parentheses. With

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread Dicebot via Digitalmars-d-learn
On Friday, 30 May 2014 at 12:35:46 UTC, francesco cattoglio wrote: Today I got the following compile error: Cannot implicitly convert expression (blabla) of type const(Type) to Type and this is a reduced example ( also on http://dpaste.dzfl.pl/f2f3bd921989): module test; import std.stdio;

Re: Differences between const Type function() and const(Type) function()

2014-05-30 Thread anonymous via Digitalmars-d-learn
On Friday, 30 May 2014 at 12:57:52 UTC, anonymous wrote: The const in the front is the same as the front in the back. ... the same as the const in the back