fork(1) download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <memory>
  4.  
  5. using namespace std;
  6. using namespace std::chrono;
  7.  
  8. enum class TYPE {base, child};
  9.  
  10. class Base {
  11. int n;
  12. protected: Base(int _n) : n(_n) {}
  13. public: virtual TYPE getType(){ return TYPE::base; }
  14. };
  15.  
  16. class Child: public Base {
  17. int m;
  18. public:
  19. TYPE getType(){ return TYPE::child; }
  20. Child(int _n, int _m) : Base(_n), m(_m) {}
  21. };
  22.  
  23. int main() {
  24. unique_ptr<Base> b = make_unique<Child>(6, 7);
  25. TYPE tB = TYPE::base;
  26. TYPE tC = TYPE::child;
  27.  
  28. {
  29. auto t1 = high_resolution_clock::now();
  30. std::cout << (tB == b->Base::getType()) << ", ";
  31. auto t2 = high_resolution_clock::now();
  32. auto duration = duration_cast<microseconds>( t2 - t1 ).count();
  33. cout << "Duration: " << duration << std::endl;
  34.  
  35. }
  36.  
  37. {
  38. auto t1 = high_resolution_clock::now();
  39. std::cout << (tC == b->getType()) << ", ";
  40. auto t2 = high_resolution_clock::now();
  41. auto duration = duration_cast<microseconds>( t2 - t1 ).count();
  42. cout << "Duration: " << duration << std::endl;
  43.  
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1, Duration: 20
1, Duration: 1