|
|
Warp wrote:
> You can't access the private variable by address. Not according to the
> standard.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1905.pdf
Section 3.9 paragraph 2, page 60 sheet 74.
#define N sizeof(T)
char buf[N];
T obj ; // obj initialized to its original value
std::memcpy(buf, &obj, N); // between these two calls to std::memcpy,
// obj might be modified
std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scalar
type
// holds its original value
Yet I'm sure at this point that there will be some reason this doesn't count
as violating modularity. Will it be that it's only a draft of the standard?
Will it be that it's only true of POD types? Will it be because it only says
it works for reading and writing all the private variables at once?
--
Darren New, San Diego CA, USA (PST)
My fortune cookie said, "You will soon be
unable to read this, even at arm's length."
Post a reply to this message
|
|