Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Obj;
  4.  
  5. class Wrapper {
  6. Obj* ptr;
  7. public:
  8. Wrapper(Obj* aptr) : ptr(aptr) {}
  9.  
  10. Obj& operator*() {
  11. return *ptr;
  12. }
  13.  
  14. operator const Obj*() {
  15. return ptr;
  16. }
  17. };
  18.  
  19. class Obj {};
  20.  
  21. void func(bool abool) {
  22. std::cout << "bool\n";
  23. }
  24.  
  25. void func(Obj* obj) {
  26. std::cout << "obj\n";
  27. }
  28.  
  29. int main() {
  30. // calls the obj variant
  31. func(new Obj());
  32.  
  33. // calls the bool variant
  34. func(Wrapper(new Obj()));
  35.  
  36. // calls the obj variant
  37. func(&*Wrapper(new Obj()));
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment