Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created November 21, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/a7212fbf5fc0152dab11cf9a5460f694 to your computer and use it in GitHub Desktop.
Save ashwin/a7212fbf5fc0152dab11cf9a5460f694 to your computer and use it in GitHub Desktop.
Example of using override and final in C++
#include <iostream>
// Virtual method declarations
struct A
{
virtual void Foo() const;
};
struct B : public A
{
void Foo() const override;
};
struct C : public B
{
void Foo() const final;
};
// Virtual method definitions
void A::Foo() const
{ std::cout << "A:foo()\n"; }
void B::Foo() const
{ std::cout << "B::foo()\n"; }
void C::Foo() const
{ std::cout << "C::foo()\n"; }
int main()
{
C c;
A *a = &c;
a->Foo();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment