CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 20

Threaded View

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    A 'customised' std::list ??

    I'm building some code which uses a library called lua. One of its header files contains a template class which (I think) is some kind of customised std::list - i.e. it's a cutdown version which only includes certain functions from a regular std::list. Here's what it looks like in the header file:-

    Code:
      template <class T>
      Class<std::list<T> > beginStdList (char const* name)
      {
        typedef std::list<T> LT;
        return beginConstStdList<T> (name)
          .addFunction("clear", (void (LT::*)()) & LT::clear)
          .addFunction("pop_front", (void (LT::*)()) & LT::pop_front)
          .addFunction("unique", (void (LT::*)()) & LT::unique) // <--- VC2019 COMPILER ERROR HERE !!
          .addFunction("push_front", (void (LT::*)(const T&)) & LT::push_front)
          .addFunction ("push_back", (void (LT::*)(const T&))&LT::push_back);
      }
    The code built fine with VC2008 - but VC2019 objects to the "unique" line which gives this compiler error if anything #incudes that header file:-


    Code:
    error C2440: 'type cast': cannot convert from 'overloaded-function' to 'void (__cdecl std::list<std::string,std::allocator<std::string>>::* )(void)'
    F:\libs\lua\LuaBridge\detail\Namespace.h(1905,24): message : None of the functions with this name in scope match the target type
    FWIW Namespace.h(1905,24) refers to the section beginning with void (LT::*)() - i.e. at the line that's failing. Does this make sense to anyone here? The function signature seem to be right AFAICT - i.e. std::list::unique() is a function which takes no parameters and returns void



    [Edit...] In case it helps, I've just found a few others which give me the same compiler error:-

    Code:
    .addFunction("front", (void (LT::*)()) & LT::front)
    .addFunction("back", (void (LT::*)()) & LT::back)
    .addFunction("end", (void (LT::*)()) & LT::end)
    Can anyone think of something which those particular functions have in common but which isn't shared by the ones that work - sort() / empty() / clear() / reverse() etc ??
    Last edited by John E; March 4th, 2021 at 06:17 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured