【发布时间】:2020-09-11 09:59:20
【问题描述】:
这段代码在 C++20 中编译(使用 gcc 10.1),在依赖类型 std::vector<T>::iterator 之前没有使用 typename 关键字。为什么会编译?
#include <vector>
template<typename T>
std::vector<T>::iterator // Why does this not require "typename" before it?
f() { return {}; }
int main() {
auto fptr = &f<int>;
}
【问题讨论】:
-
我有点惊讶标准会发现它模棱两可(因此,需要
typename),因为(我认为......)它必须是在那里输入。可能要添加language-lawyer标签。 -
C++20 允许删除一些类型名的使用。
-
@Eljay 它仍然需要知道它是一种类型;)它是一种类型是如何定义/识别“那里”的一部分。或者,更确切地说,它曾经是。
标签: c++ templates language-lawyer c++20 typename