Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MyInt {
- public:
- int myInt;
- int * space;
- MyInt(int num) : myInt(num) {
- cout << "Constructed!" << endl;
- cout << "My address:" << this << endl;
- space = new int;
- *space = num;
- cout << "space is newed!" << endl;
- }
- ~MyInt() {
- cout << "Destroyed!" << endl;
- cout << "My address:" << this << endl;
- delete space;
- cout << "space is deleted!" << endl;
- }
- MyInt plus1(MyInt n) {
- MyInt newnum (n.myInt + 1);
- cout << "I just constructed a new myInt" << endl;
- return newnum;
- }
- };
- int main() {
- MyInt m1 (3);
- cout << "Space after + 1: " << *(m1.plus1(m1)).space << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement