Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. // explicit type conversion made easy!
  2.  
  3. template<class T>
  4. struct auto_cast_t {
  5. template<class U>
  6. operator U() const { return (U)_obj; }
  7. const T _obj;
  8. };
  9.  
  10. template<class T>
  11. auto_cast_t<T> auto_cast(T obj)
  12. {
  13. auto_cast_t<T> const ret = { obj };
  14. return ret;
  15. }
  16.  
  17. int main()
  18. {
  19. int** p = auto_cast(666L);
  20. const int** q = auto_cast(p);
  21. const int *(*r)[5] = auto_cast("hello world");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement