fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T> const T *ref_to_ptr(const T &x)
  6. {
  7. return &x;
  8. }
  9.  
  10. class Test
  11. {
  12. public:
  13. Test() { cout << "ctor: " << this << endl; }
  14. ~Test() { cout << "dtor: " << this << endl; }
  15. };
  16.  
  17. void print(const Test * val)
  18. {
  19. cout << val << endl;
  20. }
  21.  
  22. int main()
  23. {
  24. print(ref_to_ptr(Test()));
  25. const Test * ptr = ref_to_ptr(Test());
  26. print(ptr);
  27. cout << "The end.\n";
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
ctor: 0x7ffc52191f9f
0x7ffc52191f9f
dtor: 0x7ffc52191f9f
ctor: 0x7ffc52191f9f
dtor: 0x7ffc52191f9f
0x7ffc52191f9f
The end.