Guest User

Untitled

a guest
Dec 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. // Compiler Default Copy Constructor
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. class Name {
  9. int m_len;
  10. char *m_p;
  11. public:
  12. Name(const char *p)
  13. {
  14. m_len = strlen(p);
  15. m_p = (char *)malloc(m_len + 1);
  16. ////
  17. strcpy(m_p, p);
  18. }
  19.  
  20. ~Name()
  21. {
  22. free(m_p);
  23.  
  24. }
  25. void display()const
  26. {
  27. // ismi ekrana yazdiralim
  28. cout << "(" << m_p << ")" << endl;
  29. }
  30. ////
  31. };
  32.  
  33.  
  34.  
  35. int main()
  36. {
  37. Name x{"Kerem Vatandas"};
  38. x.display();
  39. if (1) {
  40. Name y {x}; // CC cagirildi
  41. y.display();
  42. getchar(); // burada scope bitti, y nesnesinin destructor'i cagiralacak
  43. }
  44. // kaynak geri verildi ama x nesnesi bunun farkinda degil
  45. x.display();
  46.  
  47. return 0;
  48. }
Add Comment
Please, Sign In to add comment