An abstract class starts to make more sense when you deal with a large codebase and you are working with other devs (at least it did for me). You create one to establish a common pattern for other classes to extend and to avoid duplication of code. An abstract class cannot be instantiated but it CAN store state and concrete methods. Answer from Successful_Leg_707 on reddit.com
๐ŸŒ
Cppreference
en.cppreference.com โ€บ w โ€บ cpp โ€บ language โ€บ abstract_class.html
Abstract class - cppreference.com
Pointers and references to an abstract class can be declared. ... struct Abstract { virtual void f() = 0; // pure virtual }; // "Abstract" is abstract struct Concrete : Abstract { void f() override {} // non-pure virtual virtual void g(); // non-pure virtual }; // "Concrete" is non-abstract struct Abstract2 : Concrete { void g() override = 0; // pure virtual overrider }; // "Abstract2" is abstract int main() { // Abstract a; // Error: abstract class Concrete b; // OK Abstract& a = b; // OK to reference abstract base a.f(); // virtual dispatch to Concrete::f() // Abstract2 a2; // Error: abstract class (final overrider of g() is pure) }
๐ŸŒ
QuickStart
quickstart.com โ€บ blog โ€บ software-engineering โ€บ abstract-class-vs-interface-in-c-OOP-concepts
What Is Abstract Class vs Interface In C | OOP concepts in C
October 11, 2024 - By contrast, an interface defines a purely abstract contract. It does not provide any implemented functionality; rather, it specifies a set of methods that must be implemented by any class that adheres to the interface. In C, an interface is simulated with a structure that contains function pointers, but no actual implementation.
๐ŸŒ
TheServerSide
theserverside.com โ€บ definition โ€บ abstract-class
What is an Abstract Class? | Definition from TechTarget
Abstract classes are classes that contain one or more abstracted behaviors or methods. Objects or classes can be abstracted, which means that they're summarized into characteristics relevant to the current program's operation.
๐ŸŒ
Embedded
embedded.com โ€บ home โ€บ abstract types using c
Abstract types using C - Embedded
October 14, 2003 - An abstract type is one that's packaged to separate its functional behavior from its implementation. This lets you use an abstract type with little or no regard for its underlying implementation.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-a-cpp-abstract-class
What is a C++ abstract class?
An abstract class can have both pure virtual functions and regular methods with implementations, whereas an interface (in languages like Java or C#) typically contains only method declarations with no implementation. In C++, an abstract class is similar to an interface when it only contains pure virtual functions.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ pure-virtual-functions-and-abstract-classes
Pure Virtual Functions and Abstract Classes in C++ - GeeksforGeeks
July 15, 2014 - A class with at least one pure virtual function becomes an abstract class and Objects of abstract classes cannot be created directly. Abstract classes are used to define interfaces and ensure common structure among derived classes.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c# โ€บ c-sharp-abstract-classes
Abstract Class in C# - GeeksforGeeks
September 16, 2025 - In C#, an abstract class is a class that cannot be instantiated directly.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ cpp โ€บ abstract-classes-cpp
Abstract classes (C++) | Microsoft Learn
Access to this page requires authorization. You can try changing directories. ... Abstract classes act as expressions of general concepts from which more specific classes can be derived.
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ cpp โ€บ abstract-class-in-cpp
Abstract Class in C++ - Scaler Topics
September 27, 2021 - In C++, an abstract class is defined by having at least one pure virtual function, a function without a concrete definition. These classes are essential in object-oriented programming, structuring code to mirror real-life scenarios through inheritance and abstraction.
๐ŸŒ
Dremendo
dremendo.com โ€บ cpp-programming-tutorial โ€บ cpp-abstract-class
Abstract Class in C++ Programming | Dremendo
An abstract class is a class whose object can't be created but can be used as a base class for other classes. In C++, an abstract class is defined by including at least one pure virtual function in the class definition.
๐ŸŒ
Wikibooks
en.wikibooks.org โ€บ wiki โ€บ C++_Programming โ€บ Classes โ€บ Abstract_Classes
C++ Programming/Classes/Abstract Classes - Wikibooks, open books for an open world
January 15, 2006 - An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration.
Top answer
1 of 10
27

The purpose of an abstract class is to define a common protocol for a set of concrete subclasses. This is useful when defining objects that share code, abstract ideas, etc.

Abstract classes have no instances. An abstract class must have at least one deferred method (or function). To accomplish this in C++, a pure virtual member function is declared but not defined in the abstract class:

class MyClass {
    virtual void pureVirtualFunction() = 0;
}

Attempts to instantiate an abstract class will always result in a compiler error.

"What does defining an abstract base class provide that isn't provided by creating each necessary function in each actual class?"

The main idea here is code reuse and proper partitioning across classes. It makes more sense to define a function once in a parent class rather than defining over and over again in multiple subclasses:

class A {
   void func1();
   virtual void func2() = 0;
}

class B : public A {
   // inherits A's func1()
   virtual void func2();   // Function defined in implementation file
}

class C : public A {
   // inherits A's func1()
   virtual void func2();   // Function defined in implementation file
}
2 of 10
22

Having an abstract class like "Dog" with a virtual method like "bark" allows all classes that inherit from Dog to have their bark code called in the same way, even though the Beagle's bark is implemented way differently than the Collie's.

Without a common abstract parent (or at least a common parent with a bark virtual method) it'd be difficult to do the following:

Have a Vector of type Dog that contains Collies, Beagles, German Shepherds etc and make each of them bark. With a Vector of Dogs that contains Collies, Beagles, German Shepherds all you would have to do to make them all bark is to iterate through in a for loop and call bark on each one. Otherwise you'd have to have a separate Vector of Collies, Vector of Beagles etc.

If the question is "why make Dog abstract when it could be concrete, have a virtual bark defined with a default implementation that can be overriden?", the answer would be that this may be acceptable sometimes -- but, from a design perspective, there really isn't any such thing as a Dog that isn't a Collie or a Beagle or some other breed or mix so although they are all Dogs, there is not one of them in reality that is a Dog but not some other derived class too. Also, since dogs barking is so varied from one breed to another, there is unlikely to be any real acceptable default implementation of bark that would be acceptable for any decent group of Dogs.

I hope this helps you understand the purpose: yes, you're going to have to implement bark in each subclass anyway, but the common abstract ancestor lets you treat any subclass as a member of a base class and invoke behaviors that may be conceptually similar like bark but in fact have very different implementations.

๐ŸŒ
W3Schools
w3schools.com โ€บ cs โ€บ cs_abstract.php
C# Abstraction
Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ csharp โ€บ language-reference โ€บ keywords โ€บ abstract
abstract keyword - C# reference | Microsoft Learn
An abstract class cannot be instantiated. An abstract class may contain abstract methods and accessors. An abstract class can also contain implemented methods, properties, fields, and other members that provide functionality to derived classes. It is not possible to modify an abstract class with the sealed modifier because the two modifiers have opposite meanings.
๐ŸŒ
NDepend
blog.ndepend.com โ€บ home โ€บ abstract class vs interface in c#
Abstract Class vs Interface in C# - NDepend Blog
June 2, 2025 - Before continuing letโ€™s underline the vocabulary. We say that a class derives from a base class (abstract or not) while a class implements an interface. We say that a class is a derived class or a subclass of a base class (abstract or not) while a class is an implementation of an interface.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ understanding abstract class in c++ with example code
Understanding Abstract Class in C++ With Example Code
July 31, 2025 - Abstract class in C++ is a class that contains at least one pure virtual function. Learn all about abstract class, its syntax, characteristics, and much more!
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
Quora
quora.com โ€บ What-is-an-abstract-class-How-abstract-classes-are-similar-or-different-in-Java-from-C
What is an abstract class? How abstract classes are similar or different in Java from C++? - Quora
Answer (1 of 2): c++ *Sometimes implementation of all function cannot be provided in a base class because we donโ€™t know the implementation. Such a class is called abstract class. *For example, let Shape be a base class. We cannot provide implementation of function draw() in Shape, but we know e...