Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- using namespace std;
- void wait()
- {
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- class foo
- {
- public:
- foo () {}
- foo (int newnum)
- {
- num = newnum;
- }
- void printthis()
- {
- cout << this;
- wait();
- }
- int num;
- };
- int main()
- {
- foo myfoo, myfoo2;
- foo *ptrMyfoo = &myfoo, *ptrMyfoo2 = &myfoo2;
- cout << "This is the address of the first instance:" << endl << ptrMyfoo << endl;
- cout << "\nWhen calling foo::printthis() using the instance at " << ptrMyfoo << endl;
- cout << "the this pointer returns ";
- myfoo.printthis();
- cout << "\n\nThis is the address of the second instance:" << endl << ptrMyfoo2 << endl;
- cout << "\nWhen calling foo::printthis() using the instance at " << ptrMyfoo2 << endl;
- cout << "the this pointer returns ";
- myfoo2.printthis();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement