CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2015
    Posts
    500

    Compilation issue with the boost::assign:list_of and map_list_of

    Hello,

    I have added boost::assign:list_of and map_list_of in the following way in my project. The same compiles when I try to do the local testing with the folowing function:
    Code:
    #include <boost/assign.hpp>
    
    using namespace std;
    
    using boost::assign::list_of;
    
    using boost::assign::map_list_of;
    
    typedef map<string,int> value_type;
    typedef map<string,value_type> map_type;
    
    map_type someMap =
        boost::assign::list_of<map_type::value_type>
        ("ex",
            boost::assign::map_list_of
            ("ab", 1)
            ("xy", 2)
        )
    ;
    
    int main()
    {
    }
    But when I add as part of the Project like
    In .h file:
    Code:
    typedef map<string, int> MediaType2GBR;
    typedef map<string, MediaType2GBR> Subcat2MediaType2GBR;
    class CPCRF : public CBaseClass
    {
    public:
    	static std::map<std::string, PcrfMediaType_Value> m_mMapStringToPcrfMediaType;
    };
    And in the .cpp file:

    Code:
    Subcat2MediaType2GBR CPCRF::m_mServiceType2MediaType2GBR =
    		boost::assign::list_of<MediaType2GBR>
    		(
    		  "Gold",
    		  boost::assign::map_list_of
    		   ("Audio", 10)
    		   ("Video", 20)
    		);
    I am getting the compilation error:
    /root/SVN_ROOT/../SVN_THIRDPARTY/boost/ECX_Boost_1_63_0_tag1/x86/include/boost/preprocessor/iteration/detail/local.hpp: In member function ‘boost::assign_detail::generic_list<T>& boost::assign_detail::generic_list<T>:perator()(const U&, const U0&) [with U = char [5], U0 = boost::assign_detail::generic_list<std:air<const char*, int> >, T = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >]’:
    /root/SVN_ROOT/../SVN_THIRDPARTY/boost/ECX_Boost_1_63_0_tag1/x86/include/boost/preprocessor/iteration/detail/local.hpp:37: instantiated from ‘boost::assign_detail::generic_list<T> boost::assign::list_of(const U&, const U0&) [with T = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >, U = char [5], U0 = boost::assign_detail::generic_list<std:air<const char*, int> >]’
    ransrc/CPCRF.cpp:95: instantiated from here

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    That error is unreadable. Please use code tags to post such errors.

    You are not pasting all the code, so it's hard to follow. The .h contains an m_mMapStringToPcrfMediaType, while the .cpp talks about m_mServiceType2MediaType2GBR .
    Can you post the correct pieces of code?
    Also, post the entire error you get. I suspect that is not the entire error you are showing.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    May 2015
    Posts
    500

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    Tried to cutpaste the entire error, but codeguru is not allowing me to do so..

    Sorry the .h:

    Code:
    typedef map<string, int> MediaType2GBR;
    typedef map<string, MediaType2GBR> Subcat2MediaType2GBR;
    class CPCRF : public CBaseClass
    {
    public:
    	static Subcat2MediaType2GBR m_mServiceType2MediaType2GBR;
    };
    And in .cpp is:

    Code:
    Subcat2MediaType2GBR CPCRF::m_mServiceType2MediaType2GBR =
    		boost::assign::list_of<MediaType2GBR>
    		(
    		  "Gold",
    		  boost::assign::map_list_of
    		   ("Audio", 10)
    		   ("Video", 20)
    		);

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    Instead of boost::assign::list_of<MediaType2GBR>, you should use boost::assign::list_of<map_type::value_type>
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    May 2015
    Posts
    500

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    When I try the following:

    Subcat2MediaType2GBR CPCRF::m_mServiceType2MediaType2GBR =
    boost::assign::list_of<Subcat2MediaType2GBR::MediaType2GBR>
    (
    "Gold",
    boost::assign::map_list_of
    ("Audio", 10)
    ("Video", 20)
    );
    I get the following error:
    ransrc/CPCRF.cpp:86: error: ‘MediaType2GBR’ is not a member of ‘Subcat2MediaType2GBR’

  6. #6
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    Sorry my mistake.
    boost::assign::list_of<Subcat2MediaType2GBR::MediaType2GBR> should be boost::assign::list_of<Subcat2MediaType2GBR::value_type>
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  7. #7
    Join Date
    May 2015
    Posts
    500

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    Thanks a lot Marc, now it looks like it worked(compilation is proceeding further..hopefully finally links )

  8. #8
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Compilation issue with the boost::assign:list_of and map_list_of

    You're welcome
    Feel free to rate the answer.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Tags for this Thread

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