Overloading mess: No matching function for call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tomas

    Overloading mess: No matching function for call

    Hi.
    I wrote a code similar to this one, for a wrapper application that I
    needed:

    #include <iostream>

    using namespace std;

    class Client
    {
    public:
    void setEndpoint(con st string& s) throw() { a_endpoint = s;
    setEndpoint(); }

    protected:
    virtual void setEndpoint() throw() = 0;

    string a_endpoint;
    };

    class NotifyClient : public Client
    {
    public:
    const char* endpoint;

    private:
    void setEndpoint() throw() { endpoint = a_endpoint.c_st r(); }
    };


    int main()
    {
    NotifyClient client;
    string url("http://www.google.com" );
    client.setEndpo int( url );

    return 0;
    }


    But I'm getting this compile error with g++:

    inheritanceTopi c.cc:30: error: no matching function for call to
    `NotifyClient:: setEndpoint(std ::string&)'
    inheritanceTopi c.cc:22: note: candidates are: virtual void
    NotifyClient::s etEndpoint()

    If I change the line,

    client.setEndpo int( url );

    by

    client.Client:: setEndpoint( url );

    it works.

    I'm wondering why is it. I guess it has something to do with function
    overloading and the compiler, because if I change names, it works too.

    Can anyone give me a better explanation?
    I would like to use the same name in the functions, but I don't like
    the style of:

    client.Client:: setEndpoint( url );

    pretty ugly....

    Thanks in advance,
    Tomas.
  • sasha

    #2
    Re: Overloading mess: No matching function for call

    On Sep 29, 6:00 pm, tomas <tomaso...@gmai l.comwrote:
    Hi.
    I wrote a code similar to this one, for a wrapper application that I
    needed:
    >
    #include <iostream>
    >
    using namespace std;
    >
    class Client
    {
    public:
    void setEndpoint(con st string& s) throw() { a_endpoint = s;
    setEndpoint(); }
    >
    protected:
    virtual void setEndpoint() throw() = 0;
    >
    string a_endpoint;
    >
    };
    >
    class NotifyClient : public Client
    {
    public:
    const char* endpoint;
    >
    private:
    void setEndpoint() throw() { endpoint = a_endpoint.c_st r(); }
    >
    };
    >
    int main()
    {
    NotifyClient client;
    string url("http://www.google.com" );
    client.setEndpo int( url );
    >
    return 0;
    >
    }
    >
    But I'm getting this compile error with g++:
    >
    inheritanceTopi c.cc:30: error: no matching function for call to
    `NotifyClient:: setEndpoint(std ::string&)'
    inheritanceTopi c.cc:22: note: candidates are: virtual void
    NotifyClient::s etEndpoint()
    >
    If I change the line,
    >
    client.setEndpo int( url );
    >
    by
    >
    client.Client:: setEndpoint( url );
    >
    it works.
    >
    I'm wondering why is it. I guess it has something to do with function
    overloading and the compiler, because if I change names, it works too.
    >
    Can anyone give me a better explanation?
    I would like to use the same name in the functions, but I don't like
    the style of:
    >
    client.Client:: setEndpoint( url );
    >
    pretty ugly....
    >
    Thanks in advance,
    Tomas.
    void setEndpoint() in the NotifyClient class is private and in the
    Client is protected. You cannot lower the access level of the virtual
    function. BTW, visa verse would works.

    Comment

    • puzzlecracker

      #3
      Re: Overloading mess: No matching function for call

      On Sep 29, 6:00 pm, tomas <tomaso...@gmai l.comwrote:
      Hi.
      I wrote a code similar to this one, for a wrapper application that I
      needed:
      >
      #include <iostream>
      >
      using namespace std;
      >
      class Client
      {
      public:
      void setEndpoint(con st string& s) throw() { a_endpoint = s;
      setEndpoint(); }
      >
      protected:
      virtual void setEndpoint() throw() = 0;
      >
      string a_endpoint;
      >
      };
      >
      class NotifyClient : public Client
      {
      public:
      const char* endpoint;
      >
      private:
      void setEndpoint() throw() { endpoint = a_endpoint.c_st r(); }
      >
      };
      >
      int main()
      {
      NotifyClient client;
      string url("http://www.google.com" );
      client.setEndpo int( url );
      >
      return 0;
      >
      }
      >
      But I'm getting this compile error with g++:
      >
      inheritanceTopi c.cc:30: error: no matching function for call to
      `NotifyClient:: setEndpoint(std ::string&)'
      inheritanceTopi c.cc:22: note: candidates are: virtual void
      NotifyClient::s etEndpoint()
      >
      If I change the line,
      >
      client.setEndpo int( url );
      >
      by
      >
      client.Client:: setEndpoint( url );
      >
      it works.
      >
      I'm wondering why is it. I guess it has something to do with function
      overloading and the compiler, because if I change names, it works too.
      >
      Can anyone give me a better explanation?
      I would like to use the same name in the functions, but I don't like
      the style of:
      >
      client.Client:: setEndpoint( url );
      >
      pretty ugly....
      >
      Thanks in advance,
      Tomas.
      void setEndpoint() in the NotifyClient class is private and in the
      Client is protected. You cannot lower the access level of the virtual
      function. BTW, visa verse would works.

      Comment

      • Pete Becker

        #4
        Re: Overloading mess: No matching function for call

        On 2008-09-29 20:48:16 -0400, puzzlecracker <ironsel2000@gm ail.comsaid:
        On Sep 29, 6:00 pm, tomas <tomaso...@gmai l.comwrote:
        >Hi.
        >I wrote a code similar to this one, for a wrapper application that I
        >needed:
        >>
        >#include <iostream>
        >>
        >using namespace std;
        >>
        >class Client
        >{
        >public:
        >void setEndpoint(con st string& s) throw() { a_endpoint = s;
        >setEndpoint( ); }
        >>
        >protected:
        >virtual void setEndpoint() throw() = 0;
        >>
        >string a_endpoint;
        >>
        >};
        >>
        >class NotifyClient : public Client
        >{
        >public:
        >const char* endpoint;
        >>
        >private:
        >void setEndpoint() throw() { endpoint = a_endpoint.c_st r(); }
        >>
        >};
        >>
        >int main()
        >{
        >NotifyClient client;
        >string url("http://www.google.com" );
        >client.setEndp oint( url );
        >>
        >return 0;
        >>
        >}
        >>
        >But I'm getting this compile error with g++:
        >>
        >inheritanceTop ic.cc:30: error: no matching function for call to
        >`NotifyClient: :setEndpoint(st d::string&)'
        >inheritanceTop ic.cc:22: note: candidates are: virtual void
        >NotifyClient:: setEndpoint()
        >>
        >If I change the line,
        >>
        >client.setEndp oint( url );
        >>
        >by
        >>
        >client.Client: :setEndpoint( url );
        >>
        >it works.
        >>
        >I'm wondering why is it. I guess it has something to do with function
        >overloading and the compiler, because if I change names, it works too.
        >>
        >Can anyone give me a better explanation?
        >I would like to use the same name in the functions, but I don't like
        >the style of:
        >>
        >client.Client: :setEndpoint( url );
        >>
        >pretty ugly....
        >>
        >Thanks in advance,
        >Tomas.
        >
        void setEndpoint() in the NotifyClient class is private and in the
        Client is protected. You cannot lower the access level of the virtual
        function. BTW, visa verse would works.
        Both work. You're thinking of Java.

        The problem is that overloading only takes place among functions
        defined in the same scope. Client::setEndp oint(const string&) and
        NotifyClient::s etEndpoint() are not defined in the same scope, so they
        do not overload. The second one hides the first.

        --
        Pete
        Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
        Standard C++ Library Extensions: a Tutorial and Reference
        (www.petebecker.com/tr1book)

        Comment

        • Lars Tetzlaff

          #5
          Re: Overloading mess: No matching function for call

          tomas schrieb:
          >
          >
          But I'm getting this compile error with g++:
          >
          inheritanceTopi c.cc:30: error: no matching function for call to
          `NotifyClient:: setEndpoint(std ::string&)'
          inheritanceTopi c.cc:22: note: candidates are: virtual void
          NotifyClient::s etEndpoint()
          >
          >
          Thanks in advance,
          Tomas.
          Insert

          public:
          using Client::setEndp oint;

          into class NotifyClient, that makes both functions visible.

          Lars

          Comment

          • =?iso-8859-2?B?Smn47SBQYWxl6GVr?=

            #6
            Re: Overloading mess: No matching function for call

            On Tue, 30 Sep 2008 00:00:32 +0200, tomas <tomasorti@gmai l.comwrote:
            Hi.
            I wrote a code similar to this one, for a wrapper application that I
            needed:
            >
            #include <iostream>
            >
            using namespace std;
            >
            class Client
            {
            public:
            void setEndpoint(con st string& s) throw() { a_endpoint = s;
            setEndpoint(); }
            >
            protected:
            virtual void setEndpoint() throw() = 0;
            >
            string a_endpoint;
            };
            >
            class NotifyClient : public Client
            {
            public:
            const char* endpoint;
            >
            private:
            void setEndpoint() throw() { endpoint = a_endpoint.c_st r(); }
            };
            >
            >
            int main()
            {
            NotifyClient client;
            string url("http://www.google.com" );
            client.setEndpo int( url );
            >
            return 0;
            }
            >
            >
            But I'm getting this compile error with g++:
            >
            inheritanceTopi c.cc:30: error: no matching function for call to
            `NotifyClient:: setEndpoint(std ::string&)'
            inheritanceTopi c.cc:22: note: candidates are: virtual void
            NotifyClient::s etEndpoint()
            >
            If I change the line,
            >
            client.setEndpo int( url );
            >
            by
            >
            client.Client:: setEndpoint( url );
            >
            it works.
            >
            I'm wondering why is it. I guess it has something to do with function
            overloading and the compiler, because if I change names, it works too.
            >
            Can anyone give me a better explanation?
            This is beacuse you have a NotifyClient class and there is only one
            "setEndpoin t" function in it - the one with no parameters. The rule is,
            any member of a class shadows the members of the same name in its base
            classes. There are solutions for this.

            1) you can import Client::setEndp oint to NotifyClient via using
            declaration. However, this has the caveat that you have to do this for all
            derived classes.

            2) the simplest and easiest solution is to rename the protected
            setEndpoint() to something else - like doSetEndpoint() - and have only
            one, public, setEndpoint(str ing) function in the base class.

            Regards
            Jiri Palecek

            Comment

            Working...