[Development] Setters: Passing by value or const reference?
Alberto Mardegan
mardy at users.sourceforge.net
Wed Apr 25 12:57:31 CEST 2012
Hi Olivier,
On 04/25/2012 01:12 PM, Olivier Goffart wrote:
> The solution is actually much simpler:
>
> void Foo::setText(QString text) {
> d_ptr->text = std::move(text); // no copy
> }
>
> foo->setText(tr("hello world")); // no copy here, this is a move.
I understand why there wouldn't be a copy in the implementation of
setText, but why wouldn't calling foo->setText() produce a copy?
How can the compiler know that it must not create a copy when calling
Foo::setText(QString text) unless we are inlining it?
Ciao,
Alberto
--
http://blog.mardy.it <- geek in un lingua international!
More information about the Development
mailing list