Tutorial by Examples

The specifier override has a special meaning in C++11 onwards, if appended at the end of function signature. This signifies that a function is Overriding the function present in base class & The Base class function is virtual There is no run time significance of this specifier as is mainl...
With virtual member functions: #include <iostream> struct X { virtual void f() { std::cout << "X::f()\n"; } }; struct Y : X { // Specifying virtual again here is optional // because it can be inferred from X::f(). virtual void f() { std::cout <&lt...
C++11 introduced final specifier which forbids method overriding if appeared in method signature: class Base { public: virtual void foo() { std::cout << "Base::Foo\n"; } }; class Derived1 : public Base { public: // Overriding Base::foo void foo() f...
The behaviour of virtual functions in constructors and destructors is often confusing when first encountered. #include <iostream> using namespace std; class base { public: base() { f("base constructor"); } ~base() { f("base destructor"); } virtual co...
We can also specify that a virtual function is pure virtual (abstract), by appending = 0 to the declaration. Classes with one or more pure virtual functions are considered to be abstract, and cannot be instantiated; only derived classes which define, or inherit definitions for, all pure virtual fun...

Page 1 of 1