fork download
  1. #include <iostream>
  2.  
  3. class Printer
  4. {
  5. public:
  6. Printer() : counter(0) {}
  7. void output() const
  8. {
  9. if (counter != max_warnings)
  10. {
  11. std::cout << "Something special" << std::endl;
  12. ++counter;
  13. }
  14. }
  15. private:
  16. static const size_t max_warnings = 5;
  17. mutable size_t counter;
  18. };
  19.  
  20. int main()
  21. {
  22. const Printer printer;
  23. for (int i = 0; i < 10; ++i)
  24. {
  25. printer.output();
  26. }
  27. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Something special
Something special
Something special
Something special
Something special