what was wrong with struct & class in C++?

James Dennett jdennett at acm.org
Wed Dec 26 06:49:13 PST 2007


Walter Bright wrote:

[snip]

> In C++, one designs a class to be a reference type or a value type.

More generally, in *design*, a class either has entity semantics
(what you call "reference" types and C++ calls "polymorphic"
types) or value semantics.

That's the key terminology here, really.  What you call
reference types, C++ calls polymorphic types.  This is clearly
documented in every decent C++ library I've seen, and it just
does not lead to confusion for any competent C++ programmers.

(Possible exception: smart pointers have handle semantics:
they are copyable values, but act *like* references.)

> Interestingly, I've never once seen in documentation for a C++ class
> whether it is supposed to be used by reference or by value.

Interesting.  You've *never* seen any competent documentation
for C++ code, or you've just never been able to work out from
the documentation whether a type was polymorphic or not?

Or is this the *much* less interesting claim that the
terminology used is not the same, or that this is so obvious
that it's not explicitly flagged?

The C++ code I see (and I might say that's a fair amount) is
entirely clear on this.  I just picked a random type for which
I lacked prior knowledge of the documentation, and found
http://www.boost.org/doc/html/date_time/gregorian.html#date_time.gregorian.date_class
which says explicitly "The class is specifically designed to
NOT contain virtual functions. This design allows for efficient
calculation and memory usage with large collections of dates.",
and defines the semantics of copying.  In your terminology,
that's saying "this is a value type".

Let D stand on its own feet there's no need for misleading
FUD about C++ or the C++ community.

-- James



More information about the Digitalmars-d mailing list