const(type) vs. const type
div0
div0 at users.sourceforge.net
Tue Jul 20 16:23:23 PDT 2010
On 20/07/2010 23: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?
>
>
>
const QSize sizeHint() means the object on which you are calling the
function has to be const and the returned QSize is mutable
(I think, it might also be const as well, I don't use that format of
method signature...),
whilst const(QSize) sizeHint() means a mutable object which returns a
const object.
Const is allowed before & after the method signature which is confusing
and annoying.
In c++ it would be: (assuming QSize is a D class)
QSize& sizeHint() const { return _sh; }
vs
const QSize& sizeHint() { return _sh; }
--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
More information about the Digitalmars-d-learn
mailing list