如何识别Visual Studio中缺少的类型名
How to identify missing typename in Visual Studio
是否存在标识VS中缺少的类型名的方法?VS至少会产生某种警告吗?
template<class T>
void dum() {
std::vector<T> dum_vector;
typename std::vector<T>::iterator it = dum_vector.begin();
// VS compiles it with or without typename, but I would like to know whether
// I forgot to put a typename, since without typename the code may not compile
// with another compiler (e.g. GCC)
}
我不确定它是否具有100%的标准一致性,但对于明确需要typename
的所有或大多数情况,MSVC都会生成编译器警告(级别1)C4346。因此,只要您使用编译器标志/W1
或更高版本进行编译,您就应该没事。
实际上,在当前版本的C++(即C++11)中,您不需要写那么多。你可以这样写:
auto it = dum_vector.begin();
你就完了。
请注意,从MSVC10开始就支持auto
,所以如果您正在使用它,我建议您使用auto
来代替blah::blah::iterator
。如果您使用的是旧版本,最好升级并尽可能利用C++11功能的优势。如果您不能做到这一点,那么MSVS不太可能告诉您缺少的类型名,因为编译器首先编译的是非标准代码!
相关文章:
- C2011 'CMemDC':Visual Studio 2019中的'class'类型重新定义
- Visual Studio Code "variable " u8 的 C/C++ 扩展名 " " 不是类型名称"
- Visual Studio 2019 - 设置文件类型的默认扩展名
- Visual Studio C++:不能使用类型为 "const wchar_t *" 的值来初始化类型为 "TCHAR *" 的实体
- C++ Visual Studio 重载函数错误:没有重载函数的实例与指定的类型匹配
- Visual Studio 2017 生成工具与枚举类型的问题
- 外部 "C" Visual Studio 2015 中的显式类型错误,DLL 测试代码
- 是否可以将Visual Studio 2017将C 代码编译到EXE以外的文件类型中
- Visual studio 2013 和 g++ 7.1 中将 int 和 long 类型相乘时的 c++ 差异行为
- 在Visual Studio中,C++构建配置类型是Debug,Debug3D,DebugDLL4,DebugDLL9,
- Visual Studio 2015 C2011 'Class' 类型重定义
- 模块计算机类型和目标计算机类型 Visual Studio 2013
- 作为模板非类型参数的 C 字符串在 gcc 6.3 中有效,但在 Visual Studio 2017(x64 为 19
- 将模板类型参数的映射存储到C++中的矢量中:Visual Studio
- 自动扣除类型与尺寸的类型在Visual Studio C 和GCC之间有所不同
- 如何在 Visual Studio 2015 中将项目的配置类型动态更改为静态库?
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- 为什么我的Visual Studio 2017编译器无法识别C++17类型推导指南
- 误报警告PVS Studio:V808类型的对象是创建但未使用的
- C - Visual Studio-缺少类型的指定词 - 假设INT