CPP/StaticInheritance

From ProgrammingExamples
< CPP
Jump to: navigation, search

StaticInheritance.cpp

#include <iostream>
 
class Parent
{
public:
  static double GetValue();
};
 
double Parent::GetValue()
{
  return 2.0;
}
 
class ChildWithReimplement : public Parent
{
public:
  static double GetValue();
};
 
double ChildWithReimplement::GetValue()
{
  double parentValue = Parent::GetValue();
  return parentValue + 3.0;
}
 
class Child : public Parent
{
 
};
 
 
int main(int argc, char* argv[])
{
  std::cout << "parent: " << Parent::GetValue() << std::endl;
 
  std::cout << "child: " << Child::GetValue() << std::endl;
 
  std::cout << "ChildWithReimplement: " << ChildWithReimplement::GetValue() << std::endl;
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(StaticInheritance)
 
ADD_EXECUTABLE(StaticInheritance StaticInheritance.cpp)