本文档部分提到的文章解释了编译器生成的一部分错误消息。
重要
Visual Studio 编译器和生成工具可报告多种类型的错误和警告。 发现错误或警告后,生成工具可做出有关代码意向的假设并尝试继续,因此,可能会同时报告更多问题。 如果工具做出错误假设,则后续错误或警告可能不适于你的项目。 纠正项目中的问题时,请始终先纠正报告的第一个错误或警告,然后在通常情况下重新生成。 一个修复程序可以解决多个后续错误。
若要在 Visual Studio 中获取有关特定诊断消息的帮助内容,请在“输出”窗口中选择该消息,然后按 F1 键。 Visual Studio 会打开该错误的文档页(如果存在)。 还可以使用页面顶部的搜索工具查找有关特定错误或警告的文章。 或者,按工具浏览错误和警告列表,并在此页面上的内容列表中键入内容。
注意
并非所有 Visual Studio 错误或警告均有记录。 在许多情况下,诊断消息将提供所有可用信息。 如果登录此页面并认为错误或警告消息需要其他说明,请使用此页面上的反馈按钮告知我们。 如果认为错误或警告是错误的,或者发现了工具集的其他问题,请在开发者社区网站上报告产品问题。 还可以在 IDE 中发送反馈并输入 bug。 在 Visual Studio 中,转到菜单栏并选择 帮助 > 发送反馈 > 报告问题,或使用 帮助 > 发送反馈 > 建议功能提交建议。 创建了一些编译程序错误主题,这些主题不是由编译程序发出的,但现在会重定向到此页面。
可以在 Microsoft Q&A C++ 论坛中找到有关错误和警告的其他帮助。 或者,在 Visual Studio C++ 开发者社区网站上搜索错误或警告编号。 还可以搜索 Stack Overflow 以查找解决方案。
有关指向其他帮助和社区资源的链接,请参阅 Visual C++ 帮助和社区。
错误消息
| 错误 | Message |
|---|---|
| 编译器错误 C2900 | “declarator”:WinRT 类中的成员函数模板必须为“private”、“internal”或“protected private” |
| 编译器错误 C2901 | “identifier”:泛型接口或委托不能是公共的 |
| 编译器错误 C2902 | “token”:“template/generic”后面出现意外标记,应为标识符(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2903 | “identifier”:符号既不是类 template/generic 也不是函数 template/generic |
| 编译器错误 C2904 | “identifier”:名称已经用于当前范围内的模板 |
| 编译器错误 C2905 | 已过时。 |
| 编译器错误 C2906 | “template”:显式专用化需要“template <>” |
| 编译器错误 C2907 | 寄存器参数“number”未指定有效的寄存器编号 |
| 编译器错误 C2908 | 显式专用化;已实例化“template” |
| 编译器错误 C2909 | “identifier”:函数模板的显式实例化需要返回类型 |
| 编译器错误 C2910 | “function”:不能显式专用化 |
| 编译器错误 C2911 | “member”:无法在当前范围中声明或定义 |
| 编译器错误 C2912 | 显式专用化“declaration”不是函数模板的专用化 |
| 编译器错误 C2913 | 显式专用化;“declaration”不是类模板的专用化 |
| 编译器错误 C2914 | “identifier”:因为函数参数不明确,所以无法推导出 template/generic 参数 |
| 编译器错误 C2915 | “identifier”:不能在 WinRT 类型的发布接口上直接使用“type” 改用“Platform::Object^”传递此类型 |
| 编译器错误 C2916 | “identifier”:必须(只能)在具有“unsigned int”基础类型的公共枚举中指定 [FlagsAttribute] |
| 编译器错误 C2917 | “identifier”:无效的模板参数(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2918 | “identifier”:不能在 WinRT 类型的发布接口上使用索引属性 |
| 编译器错误 C2919 | “type”:不能在 WinRT 类型的发布接口上使用运算符 |
| 编译器错误 C2920 | 重定义:“type”:类 template/generic 已声明为“declaration” |
| 编译器错误 C2921 | 重定义:“type”:类 template/generic 将重新声明为“declaration” |
| 编译器错误 C2922 | “interface”:WinRT 接口不能包含静态成员 |
| 编译器错误 C2923 | “type”:对于参数“parameter”,“identifier”不是有效的 template/generic 类型参数 |
| 编译器错误 C2924 | __declspec(interrupt) 例程参数不在 R2 中 |
| 编译器错误 C2925 | __declspec(interrupt) 例程不能使用浮点型数值 |
| 编译器错误 C2926 | “identifier”:联合中的匿名结构的成员不允许使用默认的成员初始化表达式 |
| 编译器错误 C2927 | “identifier”:必须至少用一个参数调用函数模板 |
| 编译器错误 C2928 | 显式实例化;“identifier”不是模板类“class”的函数或静态数据成员 |
| 编译器错误 C2929 | “declarator”:显式实例化;无法显式强制和取消模板类成员的实例化 |
| 编译器错误 C2930 | “class”:template-id/generic-id 被重新定义为 “enum identifier” 的枚举器 |
| 编译器错误 C2931 | “class1”:template-id/generic-id 重新定义为“class2”的成员函数(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2932 | “type”:template-id/generic-id 重新定义为“identifier”的数据成员(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2933 | “type”:template-id/generic-id 重新定义为“identifier”的 typedef 成员(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2934 | “type”:template-id/generic-id 重新定义为“identifier”的嵌套“item”(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2935 | “type”:template-id/generic-id 重新定义为全局函数(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2936 | “type”:template-id/generic-id 重新定义为全局数据变量(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2937 | “type”:template-id/generic-id 重新定义为全局 typedef(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2938 | “identifier”:未能使别名模板专用化 |
| 编译器错误 C2939 | “type”:template-id/generic-id 重新定义为局部数据变量(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2940 | “type”:template-id/generic-id 重新定义为局部 typedef(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2941 | “type”:template-id/generic-id 重新定义为局部“item”(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2942 | “type”:template-id/generic-id 重新定义为函数的形参(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2943 | “type”:template-id/generic-id 重新定义为模板的类型参数(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2944 | “type”:template-id/generic-id 重新定义为模板的值参数(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2945 | 显式实例化不引用模板类专用化 |
| 编译器错误 C2946 | 显式实例化;“type”不是模板类专用化 |
| 编译器错误 C2947 | 要求“>”终止模板参数,找到“token” |
| 编译器错误 C2948 | 显式实例化;专用化不允许存储类说明符“specifier” |
| 编译器错误 C2949 | /kernel 不支持 thread_local |
| 编译器错误 C2950 | 已过时。 |
| 编译器错误 C2951 | template/generic 声明只能在全局、命名空间或类范围内使用 |
| 编译器错误 C2952 | “declaration”:template/generic 声明缺少 template/generic 参数列表 |
| 编译器错误 C2953 | “type”:类模板已经定义 |
| 编译器错误 C2954 | 指令字参数不在范围中 |
| 编译器错误 C2955 | “type”:使用类 template/generic 需要 template/generic 参数列表 |
| 编译器错误 C2956 | 常用解除分配函数 'function'会被选为放置解除分配函数。 |
| 编译器错误 C2957 | “token”:无效的左分隔符:应为“<” |
| 编译器错误 C2958 | 在“file(line_number)”中找到的左分隔符未正确匹配 |
| 编译器错误 C2959 | 泛型类或函数不能是模板的成员 |
| 编译器错误 C2960 | 已过时。 |
| 编译器错误 C2961 | “function”:显式实例化不一致,上一个显式实例化未指定“argument” |
| 编译器错误 C2962 | 语法错误:“token”:模板类成员函数定义应以“}”结尾 |
| 编译器错误 C2963 | 已过时。 |
| 编译器错误 C2964 | 已过时。 |
| 编译器错误 C2965 | /kernel 不支持__declspec(specifier) |
| 编译器错误 C2966 | “identifier1”:必须具有与其基类“identifier2”相同的 __declspec(code_seg(...))(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2967 | “identifier”:正在重写的虚函数必须具有与已重写的虚函数相同的 __declspec(code_seg(...))(在 Visual Studio 2022 中已过时。) |
| 编译器错误 C2968 | “identifier”:递归别名声明 |
| 编译器错误 C2969 | 语法错误:“token”:成员函数定义应以“}”结尾 |
| 编译器错误 C2970 | “type”:模板参数“parameter”:“argument”:涉及带有内部链接的对象的表达式不能用作非类型参数 |
| 编译器错误 C2971 | “type”:模板参数“parameter”:“argument”:包含非静态存储持续时间的变量不能用作非类型参数 |
| 编译器错误 C2972 | “type”:模板参数“parameter”:非类型参数的类型无效 |
| 编译器错误 C2973 | “template”:无效的模板参数“number” |
| 编译器错误 C2974 | “type”:“parameter”的 template/generic 参数无效,应为类型 |
| 编译器错误 C2975 | “type”:“parameter”的模板参数无效,应为编译时常量表达式 |
| 编译器错误 C2976 | “type”:template/generic 参数太少 |
| 编译器错误 C2977 | “type”:template/generic 参数太多 |
| 编译器错误 C2978 | 语法错误:应为“keyword1”或“keyword2”;却发现类型“type”;泛型中不支持非类型参数 |
| 编译器错误 C2979 | 泛型中不支持显式专用化 |
| 编译器错误 C2980 | C++ 异常处理不受 /kernel 支持 |
| 编译器错误 C2981 | “keyword”的动态形式不受 /kernel 支持 |
| 编译器错误 C2982 | “declaration”:使用的不同__declspec(code_seg(...)):以前是“identifier1”,现在是“identifier2” |
| 编译器错误 C2983 | “name”:定义必须与之前的声明相同__declspec(code_seg(...)) |
| 编译器错误 C2984 | 已过时。 |
| 编译器错误 C2985 | “argument”:__declspec(code_seg(...)) 的参数必须是文本部分 |
| 编译器错误 C2986 |
__declspec(code_seg(...))“”只能应用于类或函数 |
| 编译器错误 C2987 | 声明中不能同时存在 __declspec(code_seg('identifier')) 和 __declspec(code_seg('value')) |
| 编译器错误 C2988 | 不可识别的模板声明/定义 |
| 编译器错误 C2989 | “class”:类 template/generic 已经声明为非类 template/generic |
| 编译器错误 C2990 | “class”:非类 template/generic 已经声明为类 template/generic |
| 编译器错误 C2991 | 重定义 template/generic 参数“parameter” |
| 编译器错误 C2992 | “class”:template/generic 参数列表无效或缺失 |
| 编译器错误 C2993 | “type”:非类型模板参数“identifier”的类型非法 |
| 编译器错误 C2994 | 模板参数列表中未命名的类 |
| 编译器错误 C2995 | “declaration”:函数模板已经定义 |
| 编译器错误 C2996 | “function”:递归函数模板定义 |
| 编译器错误 C2997 | “function”:无法从默认的成员初始化表达式中推导数组界限 |
| 编译器错误 C2998 | “identifier”:不能是模板定义 |