Boost logo

Boost Users :

From: Liam Routt (caligari_at_[hidden])
Date: 2005-03-14 19:37:56


Part one:

I spent yesterday trying to use a char * to set the default for a
string option:

   opts.add_option("config", "Set the config file to examine",
                     po::value<string>()->default_value("newconfig"));

The result was a segmentation fault or illegal instruction during the
destruction of my opts class (a wrapper that has several
options_descriptions and a positional_options_description; there are
methods like the add_option() above that allow various options to be
set, in general they put the value_semantic argument last, but otherwise
pass arguments directly through).

So today I realized that passing a char * to something expecting a
std:string might be asking for trouble. So I tried this:

   string DefaultConfig("newconfig");
   opts.add_option("config", "Set the config file to examine",
                     po::value<string>()->default_value(DefaultConfig));

That didn't work any better. Moving the string to global scope didn't
help, nor did making it static.

So, how do I set the default for a string option?

Part two:

I want to set up a boolean option (its existence returns true, and if it
is not there it returns false). This is done using bool_switch(), I see.
However I end up with a segmentation fault if I use this following line:

   opts.add_option("bool", "testing boolean", po::bool_switch());

The fault occurs, again, when opts' destructor is running. If I leave
out the bool_switch() (ie. don't set a value semantic) I get no such
error, although the behaviour is not as I'd like it.

So, how do I use bool_switch()?

What am I missing here? It is possible I'm having trouble with all
occurences of po::value<>, as I haven't used it elsewhere yet (I'm
adding stuff gradually)...

Take care,

Liam

--
Liam Routt                                          Ph: (03) 8344-1315
Research Programmer                               caligari_at_[hidden]
Computer Science, Melbourne University              (or liam_at_[hidden])

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net