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.
这篇关于错误解决方法:“无法实例化抽象类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误解决方法:“无法实例化抽象类"
基础教程推荐
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
