gpt4 book ai didi

c++ - boost::program_options 类字段

转载 作者:太空宇宙 更新时间:2023-11-04 16:23:42 34 4
gpt4 key购买 nike

我对 boost::program_options 有疑问

我有课

namespace po = boost::program_options;
class imageProcess{
private:
po::options_description options;
public:
imageProcess(int argc,char** argv){
po::options_description desc("Allowed options");
this->options = desc;

它给了我这些错误:

non-static const member ‘const unsigned int boost::program_options::options_description::m_min_description_length’, can’t use default assignment operator imgproc line 163, external location: /usr/include/boost/program_options/options_description.hpp C/C++ Problem non-static const member ‘const unsigned int boost::program_options::options_description::m_line_length’, can’t use default assignment operator imgproc line 163, external location: /usr/include/boost/program_options/options_description.hpp C/C++ Problem use of deleted function ‘boost::program_options::options_description& boost::program_options::options_description::operator=(const boost::program_options::options_description&)’ imageProcess.cpp /imgproc/src line 20 C/C++ Problem

我应该怎么做才能创建 po::options_description 的选项字段实例?

编辑:我知道选项字段已经是一个实例但是有没有办法在定义此字段后设置描述“允许的选项”(po::options_description options(“允许的选项”);也不起作用)?我应该如何将以前创建的对象实例存储到类字段中?

最佳答案

阅读你的错误:

non-static const member ‘const unsigned int boost::program_options::options_description::m_min_description_length’, can’t use default assignment operator

non-static const member ‘const unsigned int boost::program_options::options_description::m_line_length’, can’t use default assignment operator

use of deleted function ‘boost::program_options::options_description& boost::program_options::options_description::operator=(const boost::program_options::options_description&)

它们表示boost::program_options::options_description does not support the assignment operator operator=在你的 Boost 版本中(实际上是从 v1.33 开始),由于 the const member within options_description .

你必须——而且无论如何应该——使用ctor-initializer初始化你的options_description实例:

namespace po = boost::program_options;
class imageProcess{
private:
po::options_description options;
public:
imageProcess(int argc, char** argv);
};

imageProcess::imageProcess(int argc, char** argv)
: options("Allowed options")
{}

: 开头的行是成员 options 的构造函数参数所在的位置。

关于c++ - boost::program_options 类字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14177727/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com