STL error message in g++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jfwfmt
    New Member
    • Nov 2009
    • 12

    STL error message in g++

    I'm trying to get the class multi to store a series of function/argument pairs. The functions are of the form:
    [code=c]
    string funcA (const string argA)
    [/code]

    I thought that I had all the signatures matching in:

    [code=c]
    #include <string>
    #include <queue>
    using namespace std;

    typedef string (*attr_func_T) (const string);
    typedef const string attr_arg_T;

    class multi
    {
    public:
    string invoke (void)
    {
    string ret_string;
    pair<attr_func_ T, attr_arg_T> ret_pair;
    ret_pair = call_queueX.fro nt(); /*** LINE 15 ***/
    return (ret_string);
    }
    private:
    queue <pair<attr_func _T, attr_arg_T> > call_queueX;
    }; /* class multi */
    [/code]

    I'm getting a horrible error message:

    [code=c]
    -*- mode: compilation; default-directory: "~/html/" -*-
    Compilation started at Fri Dec 18 19:51:35

    make -k CPPFLAGS=-Wno-write-strings y
    g++ -Wno-write-strings y.cpp -o y
    In file included from /usr/include/c++/4.4/bits/stl_algobase.h: 66,
    from /usr/include/c++/4.4/bits/char_traits.h:4 1,
    from /usr/include/c++/4.4/string:42,
    from y.cpp:1:
    /usr/include/c++/4.4/bits/stl_pair.h: In member function ‘std::pair<std: :string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >& std::pair<std:: string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >::operator=(co nst std::pair<std:: string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >&)’:
    /usr/include/c++/4.4/bits/stl_pair.h:68: error: non-static const member ‘const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > std::pair<std:: string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >::second’, can't use default assignment operator
    y.cpp: In member function ‘std::string multi::invoke() ’:
    y.cpp:15: note: synthesized method ‘std::pair<std: :string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >& std::pair<std:: string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >::operator=(co nst std::pair<std:: string (*)(std::string ), const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> > >&)’ first required here
    make: *** [y] Error 1

    Compilation exited abnormally with code 2 at Fri Dec 18 19:51:35
    [/code]

    NOTE: this is not for a class, it is a project i've assigned myself for my own amusement.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The queue::front() method returns a const_reference . ret_pair is not const.

    You need:

    Code:
    const pair<attr_func_T, attr_arg_T> ret_pair  = call_queueX.front();

    Comment

    • jfwfmt
      New Member
      • Nov 2009
      • 12

      #3
      Got it to work

      after making the target const and a little more massaging, the following works:

      [code=c]
      #include <string>
      #include <queue>
      using namespace std;

      typedef string (*attr_func_T) (const string);
      typedef const string attr_arg_T;

      class multi
      {
      public:
      string invoke (void)
      {
      string ret_string;
      const pair<attr_func_ T, attr_arg_T> ret_pair = call_queueX.fro nt();
      return (ret_string);
      }
      private:
      queue <pair<attr_func _T, attr_arg_T> > call_queueX;
      }; /* class multi */

      int main (int, char**) {return 0;}

      [/code]


      Thanks

      /s/ Jim WIlliams

      Comment

      Working...