473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

g++ 3.2.2 error - "no matching function for call to A::setResponse(std::wstring)"

Hi,

I am porting a piece of code from VC++ to linux platform. My compiler
is g++ 3.2.2. I am getting following error:

no matching function for call to A::setResponse(std::wstring)
candidates are A::setResponse(std::wstring &) ---> This is
indeed the signature

I am using this function as:

std::wstring A::getXMLStr()
{
std::wstring str = /* get a string from XML attribute */
return str;
}

A::setResponse(std::wstring &str)
{
this->response = str;
}

A::sendMsg()
{
this->setResponse(this->getXMLStr());
}

Can anybody please tell me whether this problem is becasue copy
constructor of std::wstring is explicit? Is this problem been fixed in
recent gcc? In that case in which version of gcc this problem is fixed?

Thanks and regards,
- Uday

Jun 7 '06 #1
3 5829
ud******@gmail.com wrote:
Hi,

I am porting a piece of code from VC++ to linux platform. My compiler
is g++ 3.2.2. I am getting following error:

no matching function for call to A::setResponse(std::wstring)
candidates are A::setResponse(std::wstring &) ---> This is
indeed the signature

I am using this function as:

std::wstring A::getXMLStr()
{
std::wstring str = /* get a string from XML attribute */
return str;
}

A::setResponse(std::wstring &str)
{
this->response = str;
}

A::sendMsg()
{
this->setResponse(this->getXMLStr());
}

Can anybody please tell me whether this problem is becasue copy
constructor of std::wstring is explicit? Is this problem been fixed in
recent gcc? In that case in which version of gcc this problem is fixed?


This is a problem in your code, which Microsoft allowed for but
shouldn't have. You are trying to bind a temporary (the returned
wstring from A::getXMLStr()) to a non-const reference, which is
illegal. You should alter the signature for A::setResponse() to one of
these:

A::setResponse(std::wstring str) // if str changes
A::setResponse(const std::wstring& str) // if str doesn't change

Also, you probably don't need all the references to "this." It is
implied and unnecessary (except in some relatively rare circumstances
with templates).

Cheers! --M

Jun 7 '06 #2
Thanks a lot. I got the point.

mlimber wrote:
ud******@gmail.com wrote:
Hi,

I am porting a piece of code from VC++ to linux platform. My compiler
is g++ 3.2.2. I am getting following error:

no matching function for call to A::setResponse(std::wstring)
candidates are A::setResponse(std::wstring &) ---> This is
indeed the signature

I am using this function as:

std::wstring A::getXMLStr()
{
std::wstring str = /* get a string from XML attribute */
return str;
}

A::setResponse(std::wstring &str)
{
this->response = str;
}

A::sendMsg()
{
this->setResponse(this->getXMLStr());
}

Can anybody please tell me whether this problem is becasue copy
constructor of std::wstring is explicit? Is this problem been fixed in
recent gcc? In that case in which version of gcc this problem is fixed?


This is a problem in your code, which Microsoft allowed for but
shouldn't have. You are trying to bind a temporary (the returned
wstring from A::getXMLStr()) to a non-const reference, which is
illegal. You should alter the signature for A::setResponse() to one of
these:

A::setResponse(std::wstring str) // if str changes
A::setResponse(const std::wstring& str) // if str doesn't change

Also, you probably don't need all the references to "this." It is
implied and unnecessary (except in some relatively rare circumstances
with templates).

Cheers! --M


Jun 7 '06 #3
On Wed, 07 Jun 2006 06:33:25 -0700, uday.sen wrote:
Hi,

I am porting a piece of code from VC++ to linux platform. My compiler is
g++ 3.2.2. I am getting following error:

no matching function for call to A::setResponse(std::wstring)
candidates are A::setResponse(std::wstring &) ---> This is
indeed the signature

I am using this function as:

std::wstring A::getXMLStr()
{
std::wstring str = /* get a string from XML attribute */ return
str;
}

A::setResponse(std::wstring &str)
{
this->response = str;
}

A::sendMsg()
{
this->setResponse(this->getXMLStr());
}

Can anybody please tell me whether this problem is becasue copy
constructor of std::wstring is explicit? Is this problem been fixed in
recent gcc? In that case in which version of gcc this problem is fixed?


gcc isn't broken, VC++ is. You may not bind a temporary to a non-const
reference. The value returned by getXMLStr is a temporary string, and
setResponse takes a non-const reference to string. Looking at the code,
your setResponse doesn't ever try to modify the passed-in value, so it
should take the parameter by const-reference.
Jun 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mr | last post by:
How can i 'force' c++ to interprete "blabla" strings as unicode string instead of ascii string (i just don't want to add 'L' before the thousands strings that are on my projects...), as all my...
2
by: Gernot Frisch | last post by:
Hi, I'm trying to make my code UNICODE safe, but there's not "_tstring" in the standard (or is there?). What is the best way to make it compatible with future versions of the standard? So...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.