// A “Loud” class. It announces whenever its methods are called. #ifndef LOUD_H_INCLUDED #define LOUD_H_INCLUDED #include class Loud { char c; void hi(const char *s) const { std::cout << "Loud::" << s; if (c) std::cout << " [c='" << c << "']"; std::cout << std::endl; // flush debug output } public: Loud(char ch = '\0') : c(ch) { hi("Loud()"); } ~Loud() { hi("~Loud()"); } Loud(const Loud &l) : c(l.c) { hi("Loud(const Loud &)"); } Loud(Loud &&l) : c(l.c) { hi("Loud(Loud &&)"); } Loud& operator=(const Loud &l) { c=l.c; hi("operator=(const Loud &)"); return *this; } Loud& operator=(Loud &&l) { c=l.c; hi("operator=(Loud &&)"); return *this; } Loud& operator=(char ch) { c = ch; hi("operator=(char)"); return *this; } Loud& operator++() { ++c; hi("operator++()"); return *this; } Loud operator++(int) { hi("operator++(int)"); const auto save = *this; ++*this; return save; } Loud operator+(const Loud &l) const { hi("operator+(const Loud &)"); return Loud(c+l.c); } }; #endif /* LOUD_H_INCLUDED */