(C++) InheritanceExample1
February 24, 2017 · View on GitHub
(C++) InheritanceExample1
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
STL: GNU ISO C++ Library, version
4.9.2
Qt project file: ./CppInheritanceExample1/CppInheritanceExample1.pro
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ -Werror SOURCES += main.cpp
./CppInheritanceExample1/main.cpp
#include <iostream> struct Person { ~Person() {} virtual void SayHello() const = 0; }; struct GrumpyPerson : public Person { void SayHello() const { std::cout << "...\n"; } }; struct HappyPerson : public Person { void SayHello() const { std::cout << "Hello!\n"; } }; int main() { //Base b; //Cannot create instance of abstract class const GrumpyPerson g; g.SayHello(); const HappyPerson h; h.SayHello(); } /* Screen output: ... Hello! Press <RETURN> to close this window... */