Menu

Why can't I do assignment with program_options::options_description?

Help
2017-02-09
2017-02-09
  • Matthew Busche

    Matthew Busche - 2017-02-09

    Hi,

    Why won't this compile?

    #include "boost/program_options.hpp"
    
    int main(int argc, char** argv)
    {
        boost::program_options::options_description od1;
        boost::program_options::options_description od2;
        od2 = od1;
        return 0;
    }
    

    g++ 4.8.4 on ubuntu gives this error:

    >  g++ foo.cpp -std=c++11 -lboost_program_options
    foo.cpp: In function int main(int, char**):
    foo.cpp:7:9: error: use of deleted function boost::program_options::options_description& boost::program_options::options_description::operator=(const boost::program_options::options_description&)
         od2 = od1;
             ^
    In file included from /usr/include/boost/program_options.hpp:15:0,
                     from foo.cpp:1:
    /usr/include/boost/program_options/options_description.hpp:173:38: note: boost::program_options::options_description& boost::program_options::options_description::operator=(const boost::program_options::options_description&) is implicitly deleted because the default definition would be ill-formed:
         class BOOST_PROGRAM_OPTIONS_DECL options_description {
                                          ^
    /usr/include/boost/program_options/options_description.hpp:173:38: error: non-static const member const unsigned int boost::program_options::options_description::m_line_length, cant use default assignment operator
    /usr/include/boost/program_options/options_description.hpp:173:38: error: non-static const member const unsigned int boost::program_options::options_description::m_min_description_length, cant use default assignment operator
    

    Curiously, the copy constructor does compile. I'm getting ready to redesign some things to avoid the copy-assign, but I don't understand why this should be disallowed.

    Thanks,
    Matt Busche

     
  • Matthew Busche

    Matthew Busche - 2017-02-09

    Never mind -- the last bit of compiler output was actually useful -- options_description has const data members that's breaking operator=(). That's annoying. I'm going to have to design around this.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.