2
변형 및 구조의 boost :: static_visitor 응용 프로그램에서 약간 혼란 스럽습니다. 나는 아래에 테스트 케이스를 포함시켰다.boost :: static_visitor에 대한 요구 사항
apply_visitor_unary.hpp : 72 : 오류 : '구조체 (S1)가'라는 이름의 멤버가없는 'apply_visitor 은 "s_visitor"의 주석 섹션, 나는 다음과 같은 오류 메시지가하거나 문제를 해결하는 방법을 발생하는 이유 이해하지 않는다 '
#include "boost/variant.hpp"
#include "iostream"
struct s1 {
int val;
s1(int a) : val(a) {}
};
struct s2 {
s1 s;
int val;
s2(int a, int b) : s(a), val(b) {}
};
struct s_visitor : public boost::static_visitor<>
{
void operator()(int & i) const
{
std::cout << "int" << std::endl;
}
void operator()(s1 & s) const
{
std::cout << "s1" << std::endl;
}
void operator()(s2 & s) const
{
std::cout << "s2" << std::endl;
// -> following 'struct s1' has no member apply_visitor
// boost::apply_visitor(s_visitor(), s.s);
// -> following 'struct s1' has no member apply_visitor
// boost::apply_visitor(*this, s.s);
s_visitor v;
v(s.s);
}
};
int main(int argc, char **argv)
{
boost::variant< int, s1, s2 > v;
s1 a(1);
s2 b(2, 3);
v = a;
boost::apply_visitor(s_visitor(), v);
v = b;
boost::apply_visitor(s_visitor(), v);
return 0;
}
도움을 주셔서 감사합니다.
@ dan10400 그런데 코드 "s_visitor v; v (s.s);" 엮다? 나는 그것이 생각할 것입니다, 또는 양자 택일로 저는 "(* this) (s.s)"이 효과가 있다고 생각합니다. – DataGraham
감사합니다. 이 예제는 구조체가 변형과 혼합 된 더 큰 예제에서 끓여서 데이터 구조를 걷는 통합 된 접근 방식을 추진하고 있다고 생각합니다. 코드 "s_visitor v; v (s.s);" 유형에 operator()를 사용하기 때문에 컴파일되고 작동합니다. 이것은 아마 내 혼란에 추가. 그러나 "(* this) (s.s)"코드는 그렇지 않습니다. – dan10400