Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6. void wait()
  7. {
  8. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  9. }
  10.  
  11. class foo
  12. {
  13. public:
  14. foo () {}
  15. foo (int newnum)
  16. {
  17. num = newnum;
  18. }
  19.  
  20. void printthis()
  21. {
  22. cout << this;
  23. wait();
  24. }
  25.  
  26. int num;
  27. };
  28.  
  29. int main()
  30. {
  31. foo myfoo, myfoo2;
  32.  
  33. foo *ptrMyfoo = &myfoo, *ptrMyfoo2 = &myfoo2;
  34.  
  35. cout << "This is the address of the first instance:" << endl << ptrMyfoo << endl;
  36. cout << "\nWhen calling foo::printthis() using the instance at " << ptrMyfoo << endl;
  37. cout << "the this pointer returns ";
  38. myfoo.printthis();
  39.  
  40. cout << "\n\nThis is the address of the second instance:" << endl << ptrMyfoo2 << endl;
  41. cout << "\nWhen calling foo::printthis() using the instance at " << ptrMyfoo2 << endl;
  42. cout << "the this pointer returns ";
  43. myfoo2.printthis();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement