fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename T> class SmartPtr
  5. {
  6. public:
  7. SmartPtr(T* data): member(data) {}
  8.  
  9. T& operator * ()
  10. {
  11. cout << "T& operator* called" << endl;
  12. return *member;
  13. }
  14.  
  15. T*& operator () ()
  16. {
  17. cout << "T*& operator () called" << endl;
  18. return member;
  19. }
  20.  
  21. operator T * ()
  22. {
  23. cout << "operator T* called" << endl;
  24. return member;
  25. }
  26.  
  27. T* member;
  28. };
  29.  
  30. int main() {
  31. int x = 10;
  32. SmartPtr<int> pT = SmartPtr<int>(&x);
  33. static_cast<int*>(pT);
  34. return 0;
  35. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
operator T* called