const(type) vs. const type

torhu no at spam.invalid
Tue Jul 20 16:08:45 PDT 2010


On 21.07.2010 00:57, Mike Linford wrote:
> I'm playing with QtD, and I tried to override a QWidget's sizeHint()
> function, which is declared as const QSize sizeHint(). I tried to
> override it by declaring my function as override const(QSize) sizeHint
> () . I got a compiler error that it was "not covariant" with const QSize,
> and when I changed it to that it worked fine. I've skimmed through the
> documentation but don't understand what the difference is. Any help?

In the first case, it's the function itself that ends up being const, 
not its return value.  It's like putting 'const' after the parameter 
list in C++.    In the second case, only the return value is const.


More information about the Digitalmars-d-learn mailing list