#include <string> class ErrorKeeper : private std::string { public: std::string get_error() const { return *this; } protected: ErrorKeeper(){} void reset_error() { erase(); } void set_error( const char* err ) { std::string::operator=( err ); } void set_error( std::string const& err ) { std::string::operator=( err ); } };//class ErrorKeeper
class Worker : public ErrorKeeper { public: void run() { reset_error(); // ... set_error( "everything ok" ); } };//class Worker #include <cassert> int main() { Worker main_thread; main_thread.run(); assert( main_thread.get_error() == "everything ok" ); return 0; }