3
boost :: program_options를 사용하면 네임 스페이스 내부에서 선언 할 때 컴파일 할 자체 옵션 유형을 가져올 수 없습니다. 그러나 컴파일하고 잘 작동 네임 스페이스의 외부 :boost :: program_options : 네임 스페이스에 속할 때 내 자신의 옵션 유형을 선언하고 유효성을 검사하는 방법은 무엇입니까?
#include <boost/program_options.hpp>
using namespace boost;
using namespace boost::program_options;
struct my_type1 {
my_type1(int nn) : n(nn) {}
int n;
};
namespace nm {
struct my_type2 {
my_type2(int nn) : n(nn) {}
int n;
};
}
void validate(boost::any& v,
const std::vector<std::string>& values,
my_type1*, int) {
const std::string& s = validators::get_single_string(values);
v = any(my_type1(lexical_cast<int>(s)));
}
void validate(boost::any& v,
const std::vector<std::string>& values,
nm::my_type2*, int) {
const std::string& s = validators::get_single_string(values);
v = any(nm::my_type2(lexical_cast<int>(s)));
}
int main() {
options_description desc("options");
desc.add_options()
("m1", value<my_type1>() , "")
("m2", value<nm::my_type2>(), "")
;
return 0;
}
)을 (주 'M1'컴파일 옵션을 선언하지만, 'm2'에서 ... 은 무엇 누락하지 않는 이유는 무엇입니까? gcc 버전 4.4.4에서 boost_1_43_0을 (를) 사용하고 있습니다. 는 IT 나를 위해 컴파일
namespace nm {
void validate(boost::any& v,
const std::vector<std::string>& values,
my_type2*, int) {
const std::string& s = validators::get_single_string(values);
v = any(my_type2(lexical_cast<int>(s)));
}
}
:에
나에게도 효과가있다. - Lars 감사. – Francois
평생 동안 나를 괴롭히는 것에 감사드립니다! –