fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. class MyClass
  5. {
  6. private:
  7. std::string mStr ;
  8.  
  9. public:
  10. MyClass(const std::string str = "empty") :mStr(str)
  11. {
  12.  
  13. }
  14. MyClass(const MyClass &obj) :
  15. mStr(obj.getString())
  16. {
  17. std::cout<<" Copy constructor "<<obj.mStr<<std::endl;
  18.  
  19. }
  20. std::string getString() const
  21. {
  22. return mStr;
  23. }
  24.  
  25. ~MyClass(void)
  26. {
  27.  
  28. }
  29. };
  30.  
  31. int main()
  32. {
  33. MyClass one("string");
  34. MyClass two(one);
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
 Copy constructor string