Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class ABC {
  2. private:
  3. int* ptr;
  4. public:
  5. ABC(int x = 0) : ptr(new int(x)) {
  6. cout << "constructeur" << endl;
  7. }
  8. bool operator == (ABC c) {
  9. return (*ptr == *(c.ptr));
  10. }
  11. ~ABC() {
  12. cout << "destructeur" << *ptr << endl;
  13. delete ptr;
  14. }
  15. ABC& operator=(ABC& other) {
  16. ptr = new int(*other.ptr);
  17.  
  18. return *this;
  19. }
  20. ABC(const ABC& a) : ptr(new int(*(a.ptr))) {
  21. cout << " constructeur de copie " << *(ptr) << endl;
  22. }
  23. };
  24.  
  25. int main() {
  26. /* 1 */ ABC c;
  27. /* 2 */ ABC c1 = 5;
  28. /* 3 */ ABC c2;
  29. /* 4 */ c2 = c1;
  30. /* 5 */ if (c1 == c2)
  31. cout << " egaux " << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement