Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ABC {
- private:
- int* ptr;
- public:
- ABC(int x = 0) : ptr(new int(x)) {
- cout << "constructeur" << endl;
- }
- bool operator == (ABC c) {
- return (*ptr == *(c.ptr));
- }
- ~ABC() {
- cout << "destructeur" << *ptr << endl;
- delete ptr;
- }
- ABC& operator=(ABC& other) {
- ptr = new int(*other.ptr);
- return *this;
- }
- ABC(const ABC& a) : ptr(new int(*(a.ptr))) {
- cout << " constructeur de copie " << *(ptr) << endl;
- }
- };
- int main() {
- /* 1 */ ABC c;
- /* 2 */ ABC c1 = 5;
- /* 3 */ ABC c2;
- /* 4 */ c2 = c1;
- /* 5 */ if (c1 == c2)
- cout << " egaux " << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement