123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|478|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Inheriting abstract classes in C++

Tue, 01 Sep 2009, 09:52
Afr0
Given the following abstract baseclass (it being abstract isn't very obvious - unlike C# where a class is marked with the 'abstract' keyword, C++ classes are automatically marked as abstract if they contain one or more pure virtual functions), why is the compiler complaining that it cannot 'instantiate abstract class' when the derived class isn't supposed to be abstract??



This is the derived class:



The class that actually generates the error is a third class that tries to define a member of the derived class, UDPListener:



More specifically, the following line generates the 'cannot instantiate abstract class' error twice;



Why? Are all inherited classes automatically abstract unless marked otherwise? o_O

|edit| Nevermind, figured it out. Needed to override Run() in the abstract class. That's what you get when you copypasta from two sources... |edit|

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 02 Sep 2009, 01:02
shroom_monk
The pure virtual functions still exist in the inherited class, so must be overridden in order for you to be able to instantiate the class. However, your void Run() function is not overridden in the derived class, so it still exists as a pure virtual function inside the derived class.

-=-=-
A mushroom a day keeps the doctor away...

Keep It Simple, Shroom!
Wed, 02 Sep 2009, 01:53
Afr0
However, your void Run() function is not overridden in the derived class, so it still exists as a pure virtual function inside the derived class.


Yeah, I realized I needed to override it, and that I wasn't doing it. Saying it still exists as a pure virtual function inside the derived class made it more clear to me why the compiler was complaining though!




-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!