Method for solving error: quot;cannot instantiate abstract classquot;(错误解决方法:“无法实例化抽象类)
问题描述
我发现对我来说最耗时的编译器错误之一是无法实例化抽象类",因为问题始终是我不希望类是抽象的,并且编译器没有列出哪些函数是抽象的.必须有一种更聪明的方法来解决这些问题,而不是阅读标题 10 次,直到我终于注意到某处缺少const".你如何解决这些问题?
I find one of the most time-consuming compiler errors for me is "cannot instantiate abstract class," since the problem is always that I didn't intend for the class to be abstract and the compiler doesn't list which functions are abstract. There's got to be a more intelligent way to solve these than reading the headers 10 times until I finally notice a missing "const" somewhere. How do you solve these?
推荐答案
无法实例化抽象类
cannot instantiate abstract class
基于此错误,我猜测您使用的是 Visual Studio(因为当您尝试实例化抽象类时,Visual C++ 就是这样说的).
Based on this error, my guess is that you are using Visual Studio (since that's what Visual C++ says when you try to instantiate an abstract class).
查看 Visual Studio 输出窗口(查看 => 输出);输出应在错误后包含一条语句,说明:
Look at the Visual Studio Output window (View => Output); the output should include a statement after the error stating:
stubby.cpp(10) : error C2259: 'bar' : cannot instantiate abstract class
due to following members:
'void foo::x(void) const' : is abstract
stubby.cpp(2) : see declaration of 'foo::x'
(这是 bdonlan 的示例代码给出的错误)
(That is the error given for bdonlan's example code)
在 Visual Studio 中,错误列表"窗口仅显示错误消息的第一行.
In Visual Studio, the "Error List" window only displays the first line of an error message.
这篇关于错误解决方法:“无法实例化抽象类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误解决方法:“无法实例化抽象类"
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07