问题
I'm trying to follow this tutorial on boost program_options, but I'm getting this error:
error: 'desc' does not name a type.
Here is the source code I have:
#include <boost/program_options.hpp>
using namespace std;
namespace po = boost::program_options;
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("compression", po::value<int>(), "set compression level")
;
int main()
{
return 0;
}
the error is on the line starting with 'desc.add_options', not the line where I construct it.
/usr/local/boost is my BOOST_ROOT, and I have it added to my code blocks compiler settings. The compiler arg is -I/usr/local/boost
Why is this not working?
回答1:
Looks like you try to use the lines
po::options_description desc("Allowed options");
desc.add_options()
on top level outside of all functions. In C++ this does not work - move this code to a function.
来源:https://stackoverflow.com/questions/25234020/c-and-boost-program-options-error-desc-does-not-name-a-type