size of Empty Class

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.
 
A

Alf P. Steinbach

* James Kanze:
[OO] has to mean something to be useful as a term. If everything
you do is OO, then the term doesn't add anything.

OO is the technique of putting knowledge of relevant routines in your data, as
opposed to the technique of putting knowledge of relevant data in your routines.


Cheers & hth.,

- Alf (definitionist)
 
B

Bo Persson

Jeff said:
So instead of "section 10.1", the official terminology is "clause
10, subclause 1"?

Probably. On the other hand, a lot of the library clauses have
subclauses starting with the phrases:

"This section contains..." or "This sections only describes...".


So it is easy to become confused. :)


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,431
Latest member
ElyseG3173

Latest Threads

Top