Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) FinalExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppFinalExample1/CppFinalExample1.pro

 

include(../../ConsoleApplication.pri)

SOURCES += main.cpp

 

 

 

 

 

./CppFinalExample1/main.cpp

 

#include <iostream>

struct Base
{
  virtual ~Base() noexcept {}
  virtual void A() const = 0;
  virtual void B() const = 0;
};

struct Derived : public Base
{
  void A() const override final { std::cout << "Derived::A\n"; } //A is final
  virtual void B() const override { std::cout << "Derived::B\n"; }
};

struct DerivedAgain : public Derived
{
  //void MakeSound() const { std::cout << "DerivedAgain::A\n"; } //will not compile: Derived::A is final
  void B() const override { std::cout << "DerivedAgain::B\n"; }
};

int main()
{
  Derived d;
  d.A();
  d.B();

  DerivedAgain da;
  da.A();
  da.B();
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml