fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. class Person
  6. {
  7. private:
  8. std::string lname;
  9. char *fname;
  10.  
  11. public:
  12. Person() : Person("{null}", "{null}") {}
  13.  
  14. Person(const std::string &ln)
  15. : Person()
  16. {
  17. lname = ln;
  18. }
  19.  
  20. Person(const std::string &ln, const char *fn)
  21. : lname(ln), fname( new char [strlen(fn) + 1] )
  22. {
  23. strcpy(fname, fn);
  24. }
  25.  
  26. ~Person()
  27. {
  28. delete [] fname;
  29. }
  30.  
  31. void Show() const
  32. {
  33. std::cout << fname << " " << lname << std::endl;
  34. }
  35.  
  36. void FormalShow() const
  37. {
  38. std::cout << lname << ", " << fname << std::endl;
  39. }
  40. };
  41.  
  42.  
  43. int main()
  44. {
  45. Person one;
  46. Person two("Smythecraft");
  47. Person three("Dimwiddy", "Sam");
  48.  
  49. one.Show();
  50. one.FormalShow();
  51.  
  52. std::cout << std::endl;
  53. two.Show();
  54. two.FormalShow();
  55.  
  56. std::cout << std::endl;
  57. three.Show();
  58. three.FormalShow();
  59. std::cout << std::endl;
  60. system("pause");
  61. }
  62.  
Success #stdin #stdout #stderr 0s 3432KB
stdin
Standard input is empty
stdout
{null} {null}
{null}, {null}

{null} Smythecraft
Smythecraft, {null}

Sam Dimwiddy
Dimwiddy, Sam

stderr
sh: pause: not found