C ++和boost program_options错误:"desc"未命名类型 [英] c++ and boost program_options error: 'desc' does not name a type
问题描述
我正在尝试遵循有关增强本教程的内容program_options ,但出现此错误:
I'm trying to follow this tutorial on boost program_options, but I'm getting this error:
错误:"desc"未命名类型.
error: 'desc' does not name a type.
这是我拥有的源代码:
#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;
}
错误出现在以'desc.add_options'开头的行上,而不是我构造错误的行上.
the error is on the line starting with 'desc.add_options', not the line where I construct it.
/usr/local/boost是我的BOOST_ROOT,我已将其添加到我的代码块编译器设置中.编译器arg是-I/usr/local/boost
/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
为什么这不起作用?
推荐答案
看起来像您尝试使用这些行
Looks like you try to use the lines
po::options_description desc("Allowed options");
desc.add_options()
在所有功能之外的顶层.在C ++中,此方法不起作用-将代码移至函数中.
on top level outside of all functions. In C++ this does not work - move this code to a function.
这篇关于C ++和boost program_options错误:"desc"未命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!