fork download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <numeric>
  6. #include <vector>
  7.  
  8. class A
  9. {
  10. public:
  11. int func()
  12. {
  13. std::cout<<"in A's func "<<std::endl;
  14. return 1;
  15. }
  16. };
  17.  
  18. class B : public A
  19. {
  20. public:
  21. bool func()
  22. {
  23. std::cout<<"in B's func "<<std::endl;
  24. return true;
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. std::vector<int> v(10, 2);
  31. std::partial_sum(v.cbegin(), v.cend(), v.begin());
  32. std::cout << "Among the numbers: ";
  33. std::copy(v.cbegin(), v.cend(), std::ostream_iterator<int>(std::cout, " "));
  34. std::cout << '\n';
  35.  
  36. if (std::all_of(v.cbegin(), v.cend(), [](int i) { return i % 2 == 0; }))
  37. std::cout << "All numbers are even\n";
  38.  
  39. std::cout << "None of them are odd\n";
  40.  
  41. struct DivisibleBy
  42. {
  43. const int d;
  44. DivisibleBy(int n) : d(n) {}
  45. bool operator()(int n) const { return n % d == 0; }
  46. };
  47.  
  48. if (std::any_of(v.cbegin(), v.cend(), DivisibleBy(7)))
  49. std::cout << "At least one number is divisible by 7\n";
  50.  
  51. //A* a = new B();
  52. //a->func();
  53.  
  54. B b;
  55. int x = b.func();
  56. std::cout<<"x = "<<x<<std::endl;
  57. bool y = b.func();
  58.  
  59. A a;
  60. a.func();
  61. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Among the numbers: 2 4 6 8 10 12 14 16 18 20 
All numbers are even
None of them are odd
At least one number is divisible by 7
in B's func 
x = 1
in B's func 
in A's func