是否允许将类模板类型参数定义为相同的名称?
Is it allowed to typedef a class template type argument into the same name?
这在MSVC中似乎可以像预期的那样编译和工作。但是,它是合法的c++代码吗?它是否保证做这里所期望的事情(即,以相同的名称将模板类型导出给结构体的用户)?
template <typename EnumType>
struct Enum
{
// There are two hard problems in CS: cache invalidation and naming things.
typedef EnumType EnumType;
};
我认为类型定义是不允许的。
14.6.1本地声明的名称(N4296)
6模板形参不能在其作用域中重新声明(包括嵌套作用域)。模板参数不能与模板名称。(例子:
<>之前模板<类T,>类Y {int T;//错误:template-parameter redeclarations无效f() {char T;//错误:template-parameter redeclarations}};template<类X>类X;//错误:template-parameter redeclarations之前- end示例]
类X>
typedef EnumType EnumType
是将模板参数重新定义为typedef-name
相关文章:
- 使用QJsEngine在Qt中注册自定义类型
- 使用用户定义的参数调用future/async并调用类方法
- 在UE4中使用未定义类型'UTextBlock'
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- 修改"std::set"中用户定义类型的值
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- 如何解决一元"*"(有"字符")错误的无效类型参数?
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 如何使自定义类型在unordered_map中用作键
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 定义模板参数的迭代器类型
- 用于定义类型定义的可变参数模板(使用 C++11)
- 模板声明中省略了c++类型参数.然而,在成员函数的定义中呢
- 用户定义的非类型参数解决方法
- 在模板类之外定义函数,同时使用类型和非类型参数
- 匹配googlemock中自定义类型的参数
- 在处理函数的部分模板专门化时,类型定义和参数包展开问题
- 是否可以基于模板类型参数的嵌套类型定义来专门化模板定义
- c++中的QML回调,参数为自定义类型
- 是否允许将类模板类型参数定义为相同的名称?