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
}
Answer from Chris Dargis on Stack Overflow
🌐
IBM
ibm.com › docs › en › zos › 2.4.0
Abstract classes (C++ only)
We cannot provide a description for this page right now
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › csharp › language-reference › keywords › abstract
abstract keyword - C# reference | Microsoft Learn
Abstract classes can contain both abstract members (which have no implementation and must be overridden in derived classes) and fully implemented members (such as regular methods, properties, and constructors).
🌐
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).
🌐
Cppreference
en.cppreference.com › w › cpp › language › abstract_class.html
Abstract class - cppreference.com
Defines an abstract type which cannot be instantiated, but can be used as a base class.
🌐
GeeksforGeeks
geeksforgeeks.org › c# › c-sharp-abstract-classes
Abstract Class in C# - GeeksforGeeks
September 16, 2025 - We can only create objects of derived classes. Abstract methods are declared in the abstract classes but do not have implementation, derived classes are required to implement them.
🌐
Tutorialspoint
tutorialspoint.com › cplusplus › cpp_interfaces.htm
Interfaces in C++ (Abstract Classes)
The purpose of an abstract class (often referred to as an ABC) is to provide an appropriate base class from which other classes can inherit. Abstract classes cannot be used to instantiate objects and serves only as an interface.
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.

Find elsewhere
🌐
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 one in which there is a declaration but no definition for a member function. The way this concept is expressed in C++ is to have the member function declaration assigned to zero. ... A pure Abstract class has only abstract member functions and no data or concrete member ...
🌐
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 - These concepts are core to object-oriented programming (OOP) and are often used to model real-world behaviors and system architectures. ... An abstract class serves as a partial implementation of an object. It can contain both implemented and ...
🌐
Embedded
embedded.com › home › abstract types using c
Abstract types using C - Embedded
October 14, 2003 - Listing 1 contains a C99 header file, ring_buffer.h , which defines ring_buffer as an abstract type with supporting functions.
🌐
Medium
medium.com › @nwonahr › interfaces-vs-abstract-classes-in-c-whats-the-difference-and-when-to-use-them-9af5ab21b1f9
Interfaces vs Abstract Classes in C#: What’s the Difference and When to Use Them | by Richard Nwonah | Medium
September 22, 2024 - If we add a Rectangle class later, it can implement the same interface but with a different implementation. An abstract class allows us to define both the implementation and the contract for derived classes.
Top answer
1 of 5
2

You should distinguish between a language construct as abstract classes and a generic concept as abstraction.

Although abstract classes may be a useful tool in creating abstractions it's not a necessary tool, neither is using that tool a guarantee that you would get a (good) abstraction.

For example there are abstractions all over the place in the C++ standard so one should not require to come up with another example.

Take for example the STL. There are a number of containers of different kind, but for example there are sequences which all conform to a common set of functions defined on them, in addition there are guaranteed complexities for different operations depending on which one you select. The abstraction here is that these are sequential containers that you can use to store data in. Although they don't use virtual functions, the implementation varies from implementation to implementation (or at least could vary), but if you use it according to the specification the actual implementation would not matter to the programmer (and most often the programmer does not dig into the actual implementation).

Another abstraction in the specification is the language itself, the execution environment specified therein and the translation process. These parts are not specified in terms of how they are implemented, but according to the expected behavior. For example normally an implementation would implement local variables by putting them on the processor stack, but that is an implementation detail that the C++ specification leaves out. The specification puts up a number of assumptions about the behavior of the execution. And you construct your program using these assumptions instead of assuming that the implementation would need to be done in a specific concrete way.

2 of 5
1

Abstraction is something very natural in every day life, it is very common to talk about something without getting into many details of the thing. You can use your car without thinking/knowing about mechanics, fluid mechanics, chemistry, engineering, etc. Abstraction in computer engineering is exactly the same thing (in general).

Yes a simple function provides an abstraction. But functions are just small parts of a software, and they are sometimes built by factoring the code (a good idea but that do not always lead to a good abstraction). An abstraction should have a clear semantic meaning not tricky.

OOP is a paradigm in witch you can built new types and let you forget about the details of them. As in an course about algorithm where one can tell you how quicksort works but never speak about the real nature of the elements they are sorting (it is certainly not an interesting point in sorting). What is interesting about object (as with your car) is the way one can manipulate an object not how the behavior is realized. I want to turn to the left by rotating the steering to the left, I don't want to know that really happens behind the scene when I do this. When I leave my car to the repair man, I let him do anything he wants on my car provided that it works as usual (he can change anything he wants behind the scene). As a user I just want to focus on the manual not the internals. So you need to make a difference in between the interface of an ideal object (the manual) and the realization of a concrete object (the internals schemas). This is what every OOP language let you write (in different ways of course you have a variety of possibilities to realize all of this).

So you want to talk about points on the plane somewhere in your code? Let's talk about the manual (a short one for the sake on simplicity). A Point is an object from which you can get its cartesian coordinates or its polar ones, right? Then its abstract, whatever a Point is obtain/realized in the software you want to be able to do this with it. So it is an abstraction:

class Point {
  public:
    virtual double getX() = 0;
    virtual double getY() = 0;
    virtual double getAngle() = 0;
    virtual double getLength() = 0;
}

This is a manual, with this you can use a point (provided you have one), then you can write a valid compilable code:

void f(Point *p) {
    cout << p->getX() << "," << p->getY() << endl;
}

Here you need to be careful, either pass a pointer or a reference. You pass an object as an abstraction, then something should happen to retrieve the realization, in C++ this necessitate reference or pointer. Note that this function does not receive a Point (a Point is an abstraction something that doesn't exists), but can receive any kind of realization of a Point (this makes a big difference). Note: that this code is compilable and remains valid while you call it with a realization of the abstraction (this can be valid for a very very long time! Code reusability, you know?)

Ok now somewhere you can realize the abstraction:

class PolarPoint : public Point {
  private:
    double angle, length;
  public:
    PolarPoint(double a,double l) : angle(a), length(l) {}
    virtual double getX() { return length*cos(angle); }
    virtual double getY() { return length*sin(angle); }
    virtual double getLength() { return length; }
    virtual double getAngle() { return angle; }
}

Somewhere you instantiate it (create an object of this concrete model and then use it (then forget about all of its specificity) :

...
Point *p = new PolarPoint(3.14/4,10.0);
f( p );
....

Remind that f has been compiled even a long time ago, but works with this new realization now! An abstraction is a kind of contract.

You can also realize in another way:

class CartesianPoint : public Point {
  private:
    double x, y;
  public:
    CartesianPoint(double x,double y) : x(x), y(y) {}
    virtual double getX() { return x; }
    virtual double getY() { return y; }
    virtual double getLength() { return /* the calculus from x/y*/; }
    virtual double getAngle() { return /* the calculus from x/y */; }
}

...
Point *p2 = new CartesianPoint(3.14/6,20.56);
f( p );
...

In this example I also used information hiding, concept related to abstraction (at least useful with abstraction). private/public is related to information hiding, which lets you enforce the hiding, meaning that the user of a class can't access (at least too easily) the details, not only he is discouraged from look at them but he can't manipulate them. Again, with your car, it is not easy to change a piston, not only because it is an inner part of the engine but also because the constructor provide many ways to hide this from you : no instruction manual to do so, special tools difficult to obtain, etc. You may know that your car has a carburetor, but you may be unable to touch it.

Beware that abstraction does not mean hiding, but just let you forget about the details if you don't want to (and in general you don't want to). Abstraction is a good way to obtain low coupling of software components.

🌐
TheServerSide
theserverside.com › definition › abstract-class
What is an Abstract Class? | Definition from TechTarget
Declaring a class as abstract means it can't be directly instantiated, which means an object can't be created from it. This protects code from being used incorrectly. Abstract classes require subclasses to further define attributes necessary ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › csharp › programming-guide › classes-and-structs › abstract-and-sealed-classes-and-class-members
Abstract and Sealed Classes and Class Members - C# | Microsoft Learn
The abstract keyword in C# creates incomplete classes and class members. The sealed keyword prevents inheritance of previously virtual classes or class members.
🌐
Standard C++
isocpp.org › wiki › faq › abcs
Inheritance — Abstract Base Classes (ABCs), C++ FAQ
At the programming language level, an ABC is a class that has one or more pure virtual member functions. You cannot make an object (instance) of an ABC. A member function declaration that turns a normal class into an abstract class (i.e., an ABC).
🌐
Educative
educative.io › answers › what-is-a-cpp-abstract-class
What is a C++ abstract class?
Try this: Create a new derived class, such as Bird, and implement the speak() function to print "The bird says: Chirp!". Add a Bird object to the animals vector in the main() function and observe the output. ... Abstract classes provide a way to define a common interface for derived classes while allowing each class to implement its specific behavior.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › pure-virtual-functions-and-abstract-classes
Pure Virtual Functions and Abstract Classes in C++ - GeeksforGeeks
October 15, 2025 - A class with at least one pure virtual function becomes an abstract class and Objects of abstract classes cannot be created directly.