Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Compiler Default Copy Constructor
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Name {
- int m_len;
- char *m_p;
- public:
- Name(const char *p)
- {
- m_len = strlen(p);
- m_p = (char *)malloc(m_len + 1);
- ////
- strcpy(m_p, p);
- }
- ~Name()
- {
- free(m_p);
- }
- void display()const
- {
- // ismi ekrana yazdiralim
- cout << "(" << m_p << ")" << endl;
- }
- ////
- };
- int main()
- {
- Name x{"Kerem Vatandas"};
- x.display();
- if (1) {
- Name y {x}; // CC cagirildi
- y.display();
- getchar(); // burada scope bitti, y nesnesinin destructor'i cagiralacak
- }
- // kaynak geri verildi ama x nesnesi bunun farkinda degil
- x.display();
- return 0;
- }
Add Comment
Please, Sign In to add comment