boost :: exception이 포함되어있을 때 2 레벨 변형 구조체에 이상한 문제가 있습니다.boost :: except와 boost :: variant의 문제
boost/exception/detail/is_output_streamable.hpp(45): error C2593: 'operator <<' is ambiguous
test.cpp(11): could be 'std::ostream &operator <<(std::ostream &,const ExpressionItem &)' [found using argument-dependent lookup]
test.cpp(8): or 'std::ostream &operator <<(std::ostream &,const StoredValue &)' [found using argument-dependent lookup]
1> while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, const boost::error_info<Tag,T>)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> and
1> [
1> Tag=boost::tag_original_exception_type,
1> T=const type_info *
1> ]
코드가 실제 코드 구조는 훨씬 더 복잡하며, 가능한 한 단순화 : 나는 오류
#include <boost/variant.hpp>
#include <boost/exception/all.hpp>
typedef boost::variant<int> StoredValue;
typedef boost::variant<StoredValue> ExpressionItem;
inline std::ostream& operator << (std::ostream & os, const StoredValue& stvalue) { return os;}
inline std::ostream& operator << (std::ostream & os, const ExpressionItem& stvalue) { return os; }
나는 그것을 컴파일하려고
다음 있습니다 : 나는 코드를 다음 한 각 변형에는 다섯 가지 하위 유형이 있습니다.내가 제거하면 #INCLUDE 부스트/예외/테스트 미리보기 다음 모든 시도, 프로그램이 제대로 컴파일 : 사용하는 경우에도 작동하기 위해서는 사업자 < <을 정의하는 방법을
void TestVariant()
{
ExpressionItem test;
std::stringstream str;
str << test;
}
은 누군가가 나에게 조언을 주 시겠어요 부스트 :: 예외? 나는 그것을 생각하지 않는다
감사와 관련
릭
나는 boost :: exception과 아무 관계가 없다고 생각한다. 그것은 출력 스트림 "operator <<"입니다. 그러나 당신이 그것을 사용하는 것처럼 변형을 사용하지 않았습니다. 나는 이것이 "스테로이드 위주의 조합"인데 적어도 2 가지 타입이 있어야한다고 생각했지만 암묵적으로 뭔가있을 수 있습니다 ... 나는 문서를 다시 방문 할 것입니다. – celavek
하나의 유형은 단지 예시 목적입니다. 내 실제 코드에는 각 변형이 다섯 가지 하위 유형이 있습니다. boost :: except가 없으면 모든 것이 제대로 작동합니다. – Rick
코드가 부스트 네임 스페이스 안에 있습니까? 출력 스트림 연산자가 예외에 대해 정의 된 것과 충돌한다고 생각합니다. 자신의 네임 스페이스에 코드를 삽입 해보십시오. – celavek