Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // explicit type conversion made easy!
- template<class T>
- struct auto_cast_t {
- template<class U>
- operator U() const { return (U)_obj; }
- const T _obj;
- };
- template<class T>
- auto_cast_t<T> auto_cast(T obj)
- {
- auto_cast_t<T> const ret = { obj };
- return ret;
- }
- int main()
- {
- int** p = auto_cast(666L);
- const int** q = auto_cast(p);
- const int *(*r)[5] = auto_cast("hello world");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement