小编use*_*688的帖子

c ++编译器将模板语法视为"<"运算符

我正在尝试编译以下代码:

struct A {
    template<int N> static void a() {}
};

template<> void A::a<5>() {}

template<class T>
struct B {
    static void b() {
        T::a<5>();
    }
};

void test() {
    A::a<5>();
    B<A>::b();
}
Run Code Online (Sandbox Code Playgroud)

和编译器解释<T::a<5>作为操作者<,从而导致错误:

invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
Run Code Online (Sandbox Code Playgroud)

有没有办法在T::a<5>没有编译器错误的情况下显式实例化?谢谢.

gcc版本4.5.1 20100924(Red Hat 4.5.1-4)(GCC)

c++ templates compiler-errors

3
推荐指数
1
解决办法
164
查看次数

标签 统计

c++ ×1

compiler-errors ×1

templates ×1