This question already has answers here:
Where and why do I have to put the “template” and “typename” keywords?

(6个答案)


3年前关闭。




因此,我收到了some code,我问了一个问题,我意识到这很令人困惑,后来将其删除:
template <typename T>
struct foo {
    typedef typename pair<T, T> PointType;
private:
    PointType point;
};

我不确定typename的定义中PointType的功能是什么。它这个关键词刚刚省略了吗?我注意到using定义中经常使用它来在类型支持中添加*_t扩展名。也许这就是这里的意图?

最佳答案

这是必需的,因为pair<T, T>dependent name,这意味着它根据foo的初始化方式而变化。

09-10 04:54
查看更多