14 Dec
2010
14 Dec
'10
12:29 a.m.
At Mon, 13 Dec 2010 18:52:34 -0500, John Dlugosz wrote:
[1
] [1.1 ] A couple of times I've run into the situation where a "new" C++ class is written to exactly match "legacy" C structures. At the edges where old code meets new code, you can cast one to the other in-place. For example, given a huge mess of data that includes oldstruct s1; you could write the line newclass& s2= reinterpret_cast (s1); because s2 is designed to exactly overlay s1.
Unless oldstruct and newclass are both POD, the above has
implementation-defined behavior. The portable way to do it, if they
indeed have the same layout, is
newclass& s2= *static_cast