J
James Kanze
It's disallowed. I'm looking at section (chapter?) 10 of the
current standard, p. 5: "A base class subobject may be of
zero size (clause 9); however, two subobjects that have the
same class type and that belong to the same most derived
object must not be allocated at the same address (5.10)."
That's what I thought, but it was late, and I couldn't find the
reference immediately. (And BTW: although the top level
divisions of the standard sure look like chapters to me, the
official nomenclature is section.)
I can see how that would be a tough thing to do, since you
don't actually know how much space the base is taking at
runtime. I'm sure somebody here could post a hack, if they
were so inclined.
You can do anything in C++. The question is: would you want to?
I don't think I've ever used memcpy in C++. I use structure
assignment instead. I wonder whether memcpy has any relative
advantages, e.g. in terms of performance. Anyway, the only
cases where I can think of memcpy being useful are for IPC via
shared memory, and for complicated buffering strategies.
No performance advantage---more likely the opposite. But it
works with arrays. I doubt I'd use it today (now that I've got
std::copy), but in the past, it has served me (in shared memory,
in fact).
I'm not thrilled that OO has come to mean that particular,
runtime-heavy school, but I think I've lost that battle.
I has to mean something to be useful as a term. If everything
you do is OO, then the term doesn't add anything. And of
course, the nice thing about C++ is that you only have to use
the technique (regardless of how you define it) when it's
appropriate. I'd categorize my applications as very OO, with a
lot of run-time dispatching (and a lot of code which handles the
objects without knowing their type), but I've still got a lot of
classes with value semantics as well.