Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > g++ 3.2.2 error - "no matching function for call to A::setResponse(std::wstring)"

Reply
Thread Tools

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

 
 
uday.sen@gmail.com
Guest
Posts: n/a
 
      06-07-2006
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

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      06-07-2006
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

 
Reply With Quote
 
 
 
 
Andre Kostur
Guest
Posts: n/a
 
      06-07-2006
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.
 
Reply With Quote
 
uday.sen@gmail.com
Guest
Posts: n/a
 
      06-07-2006
Thanks a lot. I got the point.

mlimber wrote:

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: "error: no matching function for call to " when overloadingmethod of base class Old Wolf C++ 0 01-28-2009 10:13 PM
g++ throws: error: no matching function for call to `block::block()' Alvin C++ 8 12-03-2006 10:33 PM
compilation error: "error: no matching function for call to 'String::String(String)' =?ISO-8859-1?Q?Martin_J=F8rgensen?= C++ 5 05-06-2006 03:48 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57