home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / fixed300.arj / BUG29.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-24  |  841 b   |  48 lines

  1. #if 0
  2. From:
  3. Subject: operator->() bug
  4. Status: Fixed in 3.0b3
  5. #endif
  6.  
  7. // Question : Shouldn't this operator-> overload be recursive in nature as
  8. // implied on page 337 of the ARM? this returns an error that "pointer required
  9. // before '->'...". This code works on Sun's CC (CFRONT 2.0 Based) and MAC.
  10. // 2.17 doesn't react any differently???
  11.  
  12. #include <stdio.h>
  13.  
  14. class obj;
  15.  
  16. class ref
  17. {
  18.     obj* myObj;
  19. public:
  20.     ref(obj* anObj) : myObj(anObj) {}
  21.     ref(ref& other) : myObj(other.myObj) {}
  22.     obj *operator->() {return myObj;}
  23. };
  24.  
  25. class hand
  26. {
  27.     obj *myObj;
  28. public:
  29.     hand(obj *anObj) : myObj(anObj) {}
  30.     ref operator->();
  31. };
  32.  
  33. class obj
  34. {
  35. public:
  36.     int foo();
  37. };
  38.  
  39. int obj::foo() { return 42; }
  40.  
  41. void main()
  42. {
  43.     obj mainObj;
  44.     hand mainHand(&mainObj);
  45.     int theAns = mainHand->foo();
  46.     printf("%d\n",theAns);
  47. };
  48.