c++ and boost program_options error: 'desc' does not name a type

女生的网名这么多〃 提交于 2021-01-20 09:10:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!