简体   繁体   中英

boost::any_cast throw with program options c++

I have the following code;

using namespace std;
using namespace boost::program_options;
using namespace boost::filesystem;
using namespace cv;

namespace fs = boost::filesystem;


int     frames2skip;

options_description desc("Allowed options");
desc.add_options();

("frames2skip", value<int>(&frames2skip)->default_value(2));

variables_map opts;
store(parse_command_line(argc, argv, desc), opts);

frames2skip = opts["frames2skip"].as<int>();

I get the following error after after assigning 'frames2skip' at last line:

what():  boost::bad_any_cast: failed conversion using boost::any_cast 
Aborted (core dumped)

What is wrong and how I can fix this problem?

desc.add_options();
               // ^ rogue semicolon, the next line is a separate statement made up
               // of parenthesized comma-expression and has no effect on `desc`.
("frames2skip", value<int>(&frames2skip)->default_value(2));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM