Preventing Overrides in an Inheritance Hierarchy - C++ Class

C++ examples for Class:Virtual Function

Description

Preventing Overrides in an Inheritance Hierarchy

#include <cinttypes>

class Vehicle
{
public:
  Vehicle() = default;

  virtual int GetNumberOfWheels() const
  {
    return 2;
  }
};

class Car : public Vehicle
{
public:
  Car() = default;

  int GetNumberOfWheels() const final
  {
    return 4;
  }
};

class Ferrari : public Car
{
public:
  Ferrari() = default;

  //int GetNumberOfWheels() const override
//  {
  //  return 5;
//  }
};

Related Tutorials