fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. struct point_t
  5. {
  6. T x, y, z;
  7. };
  8.  
  9. struct point_int
  10. {
  11. int x, y, z;
  12. };
  13.  
  14. int main()
  15. {
  16. std::cout << std::boolalpha << (sizeof(point_int) == sizeof(point_t<int>)) << std::endl;
  17.  
  18. point_t<int> pt {10, 20, 30};
  19.  
  20. point_int pi = *reinterpret_cast<point_int*>(&pt);
  21.  
  22. std::cout << "{" << pi.x <<"," << pi.y <<"," << pi.z << "}" << std::endl;
  23. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
true
{10,20,30}