Qt-interest Archive, March 2002
Qt/C++ question
Message 1 in thread
I've been having some problems on my system with QGLWidget::renderPixmap,
so I looked at the code:
QPixmap QGLWidget::renderPixmap( int w, int h, bool useContext )
{ QSize sz = size();
QPixmap pm( sz );
return pm;
.....
}
I thought that it is illegal (Bjarne Stroustrup, C++ Programming Language,
3d Edition, page 148)
to return a LOCAL?
(I am NOT a C++ expert, so I may be missing something!)
Message 2 in thread
The problem is when you return a reference to a local object. In this case,
just a copy of the QPixmap is returned. If the function was declared like
this, then this would be bad.
QPixmap& QGLWidget::renderPixmap( int w, int h, bool useContext )
{
etc...
}
JD
On Wednesday 06 March 2002 04:12 pm, Alan Fletcher wrote:
> I've been having some problems on my system with QGLWidget::renderPixmap,
> so I looked at the code:
>
> QPixmap QGLWidget::renderPixmap( int w, int h, bool useContext )
> { QSize sz = size();
> QPixmap pm( sz );
> return pm;
> .....
> }
>
> I thought that it is illegal (Bjarne Stroustrup, C++ Programming Language,
> 3d Edition, page 148)
> to return a LOCAL?
>
> (I am NOT a C++ expert, so I may be missing something!)
Message 3 in thread
At 03:20 PM 3/6/02 -0700, [you know who you are ] wrote:
>However, when execution leaves the scope of renderPixmap, the copy
>constructor for QPixmap is called and a copy of pm is returned.
Thanks Clinton, John, John & Jason : I KNEW I was missing
something trivial. [I'm adding a Qt front-end to a pre-ansi C system].