小编Jod*_*ebo的帖子

依赖名称的模板消除歧义

我通过编译以下示例遇到了以下问题:

template <int N>
class Matrix {
public:
    template <int Idx>
    int head() {
        return Idx;
    }
};

template <typename T>
class Test {
    static constexpr int RayDim = 3;
public:
    int func() const {
        Matrix<RayDim> yF;
        return yF.head<1>();
        //        ^ is template keyword required here?
    }
};

struct Empty {};

void test() {
    Test<Empty> t;
}
Run Code Online (Sandbox Code Playgroud)

链接到编译器资源管理器:https : //godbolt.org/z/js4XaP

该代码使用GCC 9.2和MSVC 19.22进行编译,但不能使用clang 9.0.0进行编译。Clang指出需要template关键字。如果static constexpr int RayDim = 3;移入int func() constclang接受它。

如代码块中的注释所述,是否需要template关键字yF.head<1>()

c++

8
推荐指数
1
解决办法
98
查看次数

标签 统计

c++ ×1