fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class T{
  7. private:
  8. string bar_;
  9. static const string& foo(){ static const string foo_="empty"; return foo_;}
  10.  
  11. public:
  12. T()=default;
  13. T(const string& b):bar_(b){}
  14. ~T()=default;
  15.  
  16. void put(const string& b){bar_=b;}
  17. const string& get()const{return (bar_.empty())? (foo()):(bar_);}
  18. };
  19.  
  20. int main() {
  21. // your code goes here
  22. T a;
  23. cout << "baz : [" << T("baz").get() << "]" << endl;
  24. cout << "empty : [" << a.get() << "]" << endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
baz   : [baz]
empty : [empty]