[Qt-interest] Problem with passing reference parameters
Denton Vis
vistapro7 at hotmail.com
Sat Mar 7 12:32:18 CET 2009
Thanks a lot.
"Scott Aron Bloom" <Scott.Bloom at sabgroup.com> wrote in message
news:7DB34253D57D2B47AEB656218FE6AAEF0C4C63 at onshorecs.com...
>
>
>> -----Original Message-----
>> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
>> bounces at trolltech.com] On Behalf Of Denton Vis
>> Sent: Friday, March 06, 2009 3:57 PM
>> To: qt-interest at trolltech.com
>> Subject: [Qt-interest] Problem with passing reference parameters
>>
>> Hi guys,
>> I do realize that this may be more of a C++ question. But as I have
>> encountered it while working with Qt, I will ask it here.
>> gcc allows Qt to have functions like:
>> void writeNamespace ( const QString & namespaceUri,
> const
>> QString & prefix = QString() )
>> As well as to pass object where references are required.
>>
>> But when I do write a function e.g.
>> void doSomething(std::string & s);
>> and I make a call to it using:
>> doSomething(QString("test").toStdString()) or
>> doSomething(std::string("test"));
>> the compiler complains very loudly about not finding the function
>> definition:
>> doSomething(std::string )
>> and tells me to try:
>> doSomething(std::string &)
>>
>> I must therefore first create a temporary variable and then pass it as
> a
>> reference.
>>
>> am I missing something?
>>
>> Thanks!
>
> This really does belong on a C++ group... but...
>
> Your not defining the interface as const std::string & but rather
> std::string & (missing the const)
>
> I leave it to your googling to figure out why :) Hint.. why would you
> want to be able to write to a temporary variable created on the call
> stack
>
> Scott
>
>
More information about the Qt-interest-old
mailing list