Provide a pure virtual destructor:

struct Base {
 virtual ~Base() = 0;
};

inline Base::~Base() {}

You need to provide an implementation, which you could right in the header by making it inline.


An abstract class is a class with some pure virtual function:

[...] A class is abstract if it has at least one pure virtual function. [...]

[N4431 §10.4/2]

Since you want an array of pointers to instances of (classes derived from) your abstract class, I assume you also want to be able to eventually delete and thus destruct one or more of those instances via these pointers:

Base * instance = // ... whatever ...
delete instance;

To call the correct destructor (of the derived class) in that case, the destructor has to be virtual.

So since it's virtual either way, and you don't want some pure virtual member function, it's best to make the destructor pure virtual.

To make a virtual function pure, you append the pure-specifier to its declaration:

struct Foo {
 virtual void bar(void) /* the */ = 0; // pure-specifier
};

Now, regarding the definition, you wonder why we need to provide one, since ...

[...] A pure virtual function need be defined only if called with, or as if with (12.4), the qualified-id syntax (5.1). [...]

[N4431 §10.4/2]

This is because when destructing a derived class, after the derived classes destructor has been called, the destructors of the bases classes will also be called:

struct Derived : public Base {
 ~Derived() {
  // contents
  // Base::~Base() will be called
 }
};

After executing the body of the destructor [...] a destructor for class X calls [...] the destructors for X’s direct base classes and, if X is the type of the most derived class (12.6.2), its destructor calls the destructors for X’s virtual base classes. All destructors are called as if they were referenced with a qualified name [...]

[N4431 §12.4/8]

So a definition of the pure virtual destructor if the Base class is needed. However ...

[...] A function declaration cannot provide both a pure-specifier and a definition [...]

[N4431 §10.4/2]

... so it has to be defined outside of the class definition. This could be done in a separate source file, or thanks to ...

An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case [...]

[N4431 §7.1.2/4]

... as a inline function in the header.


The standard is even explicit about the requirement of a definition in this case:

A destructor can be declared virtual (10.3) or pure virtual (10.4); if any objects of that class or any derived class are created in the program, the destructor shall be defined. [...]

[N4431 §12.4/9]

Answer from Daniel Jour on Stack Overflow
🌐
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.
🌐
W3Schools
w3schools.com › cs › cs_abstract.php
C# Abstraction
To access the abstract class, it must be inherited from another class. Let's convert the Animal class we used in the Polymorphism chapter to an abstract class. Remember from the Inheritance chapter that we use the : symbol to inherit from a class, and that we use the override keyword to override the base class method.
Discussions

C++: How to create an abstract base class if class has no member functions? - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I have an abstract base class, which serves the purpose of allowing an ... More on stackoverflow.com
🌐 stackoverflow.com
Declare abstract class in c++ - Stack Overflow
I frequently have base classes that have constants, variables, and functions that the derived classes use. The derived classes merely add functionality. Because of this, I have no virtual functions in the base class. I would like the ability to treat the class as abstract in case I decide to ... More on stackoverflow.com
🌐 stackoverflow.com
Good practice to design a ABC(Abstract Base Class) in C++ - Stack Overflow
You cannot create an instance of an abstract class. Better hide an implementation of constructor and destructor inside a source file not to pollute other object files. Make your interface non-copyable. If this is an interface, better do not have any variables there. Otherwise it would be an abstract base ... More on stackoverflow.com
🌐 stackoverflow.com
c++ abstract base class private members - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Just wanted some clarification. Should abstract base classes never have ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
IBM
ibm.com › docs › en › i › 7.5.0
Abstract classes (C++ only)
We cannot provide a description for this page right now
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › pure-virtual-functions-and-abstract-classes
Pure Virtual Functions and Abstract Classes in C++ - GeeksforGeeks
October 15, 2025 - A pure virtual function is a virtual function with no implementation in the base class, declared using = 0. A class with at least one pure virtual function is an abstract class that cannot be instantiated and serves as a blueprint for derived classes, which must provide their own implementation.
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › abstract-base-class
Abstract Base Class - an overview | ScienceDirect Topics
There is no definition of a pure virtual function in the base class. A class that includes a pure virtual function is referred to as an abstract base class, and instances cannot be declared from an abstract class. For example, the base class Shape is an abstract class by virtue of the pure ...
Top answer
1 of 3
14

Provide a pure virtual destructor:

struct Base {
 virtual ~Base() = 0;
};

inline Base::~Base() {}

You need to provide an implementation, which you could right in the header by making it inline.


An abstract class is a class with some pure virtual function:

[...] A class is abstract if it has at least one pure virtual function. [...]

[N4431 §10.4/2]

Since you want an array of pointers to instances of (classes derived from) your abstract class, I assume you also want to be able to eventually delete and thus destruct one or more of those instances via these pointers:

Base * instance = // ... whatever ...
delete instance;

To call the correct destructor (of the derived class) in that case, the destructor has to be virtual.

So since it's virtual either way, and you don't want some pure virtual member function, it's best to make the destructor pure virtual.

To make a virtual function pure, you append the pure-specifier to its declaration:

struct Foo {
 virtual void bar(void) /* the */ = 0; // pure-specifier
};

Now, regarding the definition, you wonder why we need to provide one, since ...

[...] A pure virtual function need be defined only if called with, or as if with (12.4), the qualified-id syntax (5.1). [...]

[N4431 §10.4/2]

This is because when destructing a derived class, after the derived classes destructor has been called, the destructors of the bases classes will also be called:

struct Derived : public Base {
 ~Derived() {
  // contents
  // Base::~Base() will be called
 }
};

After executing the body of the destructor [...] a destructor for class X calls [...] the destructors for X’s direct base classes and, if X is the type of the most derived class (12.6.2), its destructor calls the destructors for X’s virtual base classes. All destructors are called as if they were referenced with a qualified name [...]

[N4431 §12.4/8]

So a definition of the pure virtual destructor if the Base class is needed. However ...

[...] A function declaration cannot provide both a pure-specifier and a definition [...]

[N4431 §10.4/2]

... so it has to be defined outside of the class definition. This could be done in a separate source file, or thanks to ...

An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case [...]

[N4431 §7.1.2/4]

... as a inline function in the header.


The standard is even explicit about the requirement of a definition in this case:

A destructor can be declared virtual (10.3) or pure virtual (10.4); if any objects of that class or any derived class are created in the program, the destructor shall be defined. [...]

[N4431 §12.4/9]

2 of 3
2

Is it possible to create a memberless abstract base class?

The simplest way is to make the destructor pure virtual.

class AbstractBase
{
   public:
      virtual ~AbstractBase() = 0;
};
Find elsewhere
🌐
Standard C++
isocpp.org › wiki › faq › abcs
Inheritance — Abstract Base Classes (ABCs), C++ FAQ
This forces any actual object created from a [concrete] class derived from Shape to have the indicated member function, even though the base class doesn’t have enough information to actually define it yet. Note that it is possible to provide a definition for a pure virtual function, but this usually confuses novices and is best avoided until later. If the class “owns” the object pointed to by the (abstract) base class pointer, use the Virtual Constructor Idiom in the (abstract) base class.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › c# › c-sharp-abstract-classes
Abstract Class in C
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.
Top answer
1 of 4
11
  1. Do not provide an implementation for pure virtual methods unless it is necessary.
  2. Do not make your destructor pure virtual.
  3. Do not make your constructor protected. You cannot create an instance of an abstract class.
  4. Better hide an implementation of constructor and destructor inside a source file not to pollute other object files.
  5. Make your interface non-copyable.

If this is an interface, better do not have any variables there. Otherwise it would be an abstract base class and not an interface.

Too many pure functions is OK unless you can do it with less pure functions.

2 of 4
9

In C++, generally speaking, we should avoid the usage of multiple inheritance

Like any other language feature, you should use multiple inheritance wherever it is appropriate. Interfaces are generally considered an appropriate use of multiple inheritance (see, for example, COM).

The constructor of ABC needs not be protected--it cannot be constructed directly because it is abstract.

The ABC destructor should not be declared as pure virtual (it should be declared as virtual, of course). You should not require derived classes to implement a user-declared constructor if they do not need one.

An interface should not have any state, and thus should not have any member variables, because an interface only defines how something is to be used, not how it is to be implemented.

ABC should never have too many member functions; it should have exactly the number that are required. If there are too many, you should obviously remove the ones that are not used or not needed, or refactor the interface into several more specific interfaces.

🌐
Educative
educative.io › answers › what-are-abstract-base-classes
What are abstract base classes?
Abstract base classes are implemented differently in different programming languages. In C++, an abstract base class is a base class that has at least one pure virtual function. We cannot create an object of an abstract base class.
Top answer
1 of 6
17

In C++ you can have an abstract class that has non pure virtual methods. In that case, and depending on the design it can make sense to have private members:

class base {
   std::string name;
public:
   base( std::string const & n ) : name(n) {}
   std::string const & getName() const { return name; }

   virtual void foo() = 0;
};

That code ensures that every object that derives from base has a name, that is set during construction and never changes during the lifetime of the object.

EDIT: For completion after Charles Bailey reminded me of it in his answer

You can also define pure-virtual functions, and in that case, private attributes could also make sense:

// with the above definition of base
void base::foo() {
   std::cout << "My name is " << name << std::endl;
}
2 of 6
3

It's normally not advisable to have data members in an abstract class but there is nothing technically wrong with your example. In the implementation of foo, which is publicly accessible you can use myInt for whatever purposes you like.

For example:

class abc{
public:
  virtual void foo()=0;
private:
  int myInt;
};

class xyz : public abc
{
    virtual void foo();
};

#include <iostream>
#include <ostream>

void xyz::foo()
{
    std::cout << "xyz::foo()\n";
    abc::foo();
}

void abc::foo()
{
    std::cout << "abc::foo(): " << myInt++ << '\n';
}

#include <memory>

int main()
{
    std::auto_ptr<abc> p( new xyz() ); // value-initialization important
    p->foo();
    p->foo();
}

Output:

xyz::foo()
abc::foo(): 0
xyz::foo()
abc::foo(): 1
🌐
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 - In languages like C++, a class can inherit from only one abstract class, meaning you can only extend from one base class. This restriction encourages a clear hierarchy where a derived class extends from a parent and inherits its behavior. However, in C, abstract classes are simulated using structures, so direct inheritance is not a language feature.
🌐
Embedded
embedded.com › home › abstract types using c
Abstract types using C - Embedded
October 14, 2003 - In C99, you'd probably declare this function with the keyword inline to eliminate the function call overhead. In earlier C dialects, you might implement it as a macro: ... Listing 1 contains a C99 header file, ring_buffer.h , which defines ...
🌐
Cplusplus
cplusplus.com › forum › beginner › 230144
'Pure Abstract Base Class' - C++ Forum
February 8, 2018 - My first question is, is there even a concept of 'Pure Abstract Base Class' in C++? What I know: In C++ an abstract class is one which cannot be instantiated that implements at least one pure virtual function that must be overridden in any class that derives from it.
🌐
HowDev
how.dev › answers › what-are-abstract-base-classes
What are abstract base classes?
Abstract base classes are implemented differently in different programming languages. In C++, an abstract base class is a base class that has at least one pure virtual function. We cannot create an object of an abstract base class.
🌐
Python
docs.python.org › 3 › library › abc.html
abc — Abstract Base Classes
In addition, the collections.abc submodule has some ABCs that can be used to test whether a class or instance provides a particular interface, for example, if it is hashable or if it is a mapping. This module provides the metaclass ABCMeta for defining ABCs and a helper class ABC to alternatively define ABCs through inheritance: ... A helper class that has ABCMeta as its metaclass. With this class, an abstract base class can be created by simply deriving from ABC avoiding sometimes confusing metaclass usage, for example:
🌐
Quora
quora.com › Why-do-we-use-abstract-classes-as-a-base-instead-of-concrete-classes-in-C++-They-do-the-exact-same-thing-except-instantiating-so-why-bother
Why do we use abstract classes as a base instead of concrete classes, in C++? They do the exact same thing, except instantiating, so why bother? - Quora
... Using an abstract class (one that contains at least one pure virtual function) as a base instead of a concrete class is not just about preventing instantiation — it’s a design tool that expresses intent, enforces constraints, and enables ...