Why compile error with enable_if

前端 未结 5 1936
小蘑菇
小蘑菇 2020-12-09 07:50

Why this does not compile with gcc48 and clang32?

#include 

template  
struct S {

    template 
    typename         


        
5条回答
  •  误落风尘
    2020-12-09 08:39

    For this case you could think about not using enable_if at all. It is posible to simply specialise f:

    template  
    struct S {
        template int f(T t);
    };
    
    template
    template
    int S::f(T t) { return 2; }
    
    template<>
    template
    int S<1>::f(T t) { return 1; }
    
    int main() {
        S<1> s1;
        return s1.f(99);
    }
    

提交回复
热议问题