2014-01-07 2 views
2

오류의 성격이 this thread에서 언급 한 것과 다릅니다.
클래스에 멤버 (메서드)가 포함되어 있는지없는 VC++ 환경에서 SFINAE 방법을 구현하려고합니다. 여기 MethodVC++ SFINAE에서 C2070 오류가 발생합니다. 'overloaded-function': 잘못된 피연산자 크기

template<typename Class> 
class HasMember_Method 
{ 
    typedef char (&yes)[2]; 

    template<unsigned int> struct Exists; 

    template<typename V> 
    static yes CheckMember (Exists<sizeof(&V::Method)>*); // <--- VC++ problem 
    template<typename> 
    static char CheckMember (...); 

public: 
    static const bool value = (sizeof(CheckMember<Class>(0)) == sizeof(yes)); 
}; 

우리가 찾고있는 멤버 방법 :

다음은 그에 대한 단순화 된 코드입니다. 이 코드는 C++ 11이 없어도 g++ environment에서 완벽하게 작동합니다.
그러나 ++ 버그 VC에 대한 컴파일러 오류에 동일한 결과 :

오류 C2070 : '오버로드 기능'불법는 sizeof 내가 decltype를 사용 SFINAE 다른 해결 방법을 시도

피연산자하지만, 행운 . 이 문제에 대한 해결 방법이 있습니까?

+0

[MSDN 말한다] (http://msdn.microsoft.com /en-us/library/hh567368.aspx) 그들은 VS2013에서도 "Expression SFINAE"를 지원하지 않습니다. – dyp

+0

어떤 VC 버전을 사용합니까? – Jarod42

+0

@ Jarod42, VS2010/12에서는 작동하지 않습니다. 오류 .Dyp, C++을 사용하는 다른 방법 11? – iammilind

답변

2

아래는 올바른 대답이 아니지만 최소한 문제를 해결합니다. 코드 스 니펫에서 두 줄을 변경했습니다.

template<typename Class> 
class HasMember_Method 
{ 
    typedef char (&yes)[2]; 

    template<typename> struct Exists; // <--- changed 

    template<typename V> 
    static yes CheckMember (Exists<decltype(&V::Method)>*); // <--- changed (c++11) 
    template<typename> 
    static char CheckMember (...); 

public: 
    static const bool value = (sizeof(CheckMember<Class>(0)) == sizeof(yes)); 
}; 

그리고 VS2010/12의 컴파일 문제가 해결되었습니다!

대기! 버그가있는 VC++ 컴파일러의 또 다른 결함이 발견되었습니다.
항상 사실이됩니다. :(여기
good old g++ works 벌금뿐만 아니라.

그래서 정답은 이러한 문제를 해결하기 위해 마이크로 소프트 VC++ 컴파일러 팀 기다리는 것입니다.

관련 문제