用于解决错误的方法:“不能实例化抽象类” [英] Method for solving error: "cannot instantiate abstract class"
问题描述
我发现对我来说最耗时的编译器错误之一是无法实例化抽象类,因为问题总是我不打算让类抽象,编译器不列出哪些函数是抽象的。有一个更聪明的方法来解决这些比阅读头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输出窗口(View => Output);输出应该包含错误后的语句陈述:
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.
这篇关于用于解决错误的方法:“不能实例化抽象类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!