Search code examples
c++referenceabstract

reference to abstract class


What does it mean when there is a reference to an abstract class? I found it in code and I can't understand it.

I thought that an abstract class can't be instantiated. How can you give it a reference?


Solution

  • A reference to an abstract class is just like a pointer to an abstract class: it needs to reference an object of some non-abstract subclass of the abstract class. You can use a reference like that to call virtual methods on the referenced class using the . syntax, in a way similar to a pointer to an interface in Java.