fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. class Figure {
  6. public:
  7. virtual void print() const = 0;
  8. };
  9.  
  10. class Circle : public Figure {
  11. public:
  12. void print() const override {
  13. cout << "Circle" << endl;
  14. }
  15. };
  16.  
  17. class Triangle : public Figure {
  18. public:
  19. void print() const override {
  20. cout << "Triangle" << endl;
  21. }
  22. };
  23.  
  24. template <typename T>
  25. void log(const T &figure) {
  26. static_assert(std::is_base_of<Figure, T>::value,
  27. "It has to be a Figure");
  28.  
  29. figure.print();
  30. }
  31.  
  32. int main() {
  33. Circle circle;
  34. Triangle triangle;
  35.  
  36. log(circle);
  37. log(triangle);
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
Circle
Triangle