Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

c++ - Method for solving error: "cannot instantiate abstract class"

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

cannot instantiate abstract class

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).

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'

(That is the error given for bdonlan's example code)

In Visual Studio, the "Error List" window only displays the first line of an error message.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...