Flow 1.0.1
Flow project: Public API.
Public Member Functions | List of all members
flow::util::Null_interface Class Referenceabstract

An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plate-reducing base for any other (presumably virtual-method-having) class that would otherwise require a default virtual destructor. More...

#include <util.hpp>

Inheritance diagram for flow::util::Null_interface:
[legend]

Public Member Functions

virtual ~Null_interface ()=0
 Boring virtual destructor. More...
 

Detailed Description

An empty interface, consisting of nothing but a default virtual destructor, intended as a boiler-plate-reducing base for any other (presumably virtual-method-having) class that would otherwise require a default virtual destructor.

Usually, if you have a base class C at the top of a virtual-method-having hierarchy, then it needs a virtual destructor, even if it is = default or {}. Otherwise, trying to delete an object of subclass C2 : public C via a C* pointer will fail to call destructor ~C2() – which may not be empty, causing leaks and so on. Declaring ~C() and its empty implementation is surprisingly verbose. So, instead, don't; and publicly derive from Null_interface instead.

It is particularly useful for interface classes.

Constructor & Destructor Documentation

◆ ~Null_interface()

flow::util::Null_interface::~Null_interface ( )
pure virtualdefault

Boring virtual destructor.

Why is it pure? Main reason: Then Null_interface becomes abstract and cannot be itself instantiated, which is good. Otherwise we'd need a protected constructor or something to prevent it.

I (ygoldfel) actually thought this means a subclass has to now define a body (even if merely = default or {}): but no: the compiler will (and must) generate an empty (and, because of us, virtual) destructor for any subclass that doesn't explicitly define one. A destructor isn't a regular method, so that's how it works. There will not be a linker error.


The documentation for this class was generated from the following files: