fork(2) download
  1. template<typename T>
  2. struct ActualType { typedef T type; };
  3. template<typename T>
  4. struct ActualType<T*> { typedef typename ActualType<T>::type type; };
  5.  
  6. template<typename T>
  7. typename ActualType<T>::type ActualValue (T &obj) { return obj; }
  8. template<typename T>
  9. typename ActualType<T>::type ActualValue (T *p) { return ActualValue(*p); }
  10.  
  11. template<typename T>
  12. struct MyPointer
  13. {
  14. T p;
  15. typename ActualType<T>::type operator *() { return ActualValue(p); }
  16. };
  17.  
  18. int main ()
  19. {
  20. MyPointer<int*> obj1; // pointer as template
  21. int i = *obj1; // do dereferencing
  22.  
  23. MyPointer<int> obj2; // simple type as template
  24. i = *obj2; // do dereferencing
  25. }
  26.  
Success #stdin #stdout 0.01s 2720KB
stdin
Standard input is empty
stdout
Standard output is empty