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

Discussion in 'C++' started by uday.sen@gmail.com, Jun 7, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. mlimber Guest

    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
     
    mlimber, Jun 7, 2006
    #2
    1. Advertising

  3. Andre Kostur Guest

    Re: g++ 3.2.2 error - "no matching function for call to

    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.
     
    Andre Kostur, Jun 7, 2006
    #3
  4. Guest

    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
     
    , Jun 7, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hfk0
    Replies:
    2
    Views:
    21,675
  2. JavaQueries
    Replies:
    1
    Views:
    3,675
    John C. Bollinger
    Mar 1, 2005
  3. Balaji
    Replies:
    3
    Views:
    10,115
  4. Bishop
    Replies:
    1
    Views:
    791
    Bishop
    Feb 24, 2007
  5. juvi
    Replies:
    3
    Views:
    1,054
    Alexey Smirnov
    Jan 22, 2009
Loading...

Share This Page