我正在使用 boost::program_options 来解析程序的命令行,并且在尝试将值读取到也在命名空间中的类中的公共枚举中时遇到问题。
规格:
Boost 1.44.0
g++ 4.4.7
Run Code Online (Sandbox Code Playgroud)
我尝试按照Boost Custom Validator for Enum中阐述的过程进行操作,但它对我不起作用。
参数.h
#include <istream>
namespace SA
{
class Parameters
{
public:
enum Algorithm
{
ALGORITHM_1,
ALGORITHM_2,
ALGORITHM_3,
ALGORITHM_4
};
friend istream& operator>> (istream &in, Parameters::Algorithm &algorithm);
Algorithm mAlgorithm;
<More Parameters>
}
}
Run Code Online (Sandbox Code Playgroud)
参数.cpp
#include <boost/algorithm/string.hpp>
using namespace SA;
istream& operator>> (istream &in, Parameters::Algorithm &algorithm)
{
string token;
in >> token;
boost::to_upper (token);
if (token == "ALGORITHM_1")
{
algorithm = ALGORITHM_1;
}
else if (token == "ALGORITHM_2")
{ …Run Code Online (Sandbox Code Playgroud)