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

Russell Lewis webmaster at villagersonline.com
Wed Dec 12 10:46:29 PST 2007


BC wrote:
> I thought it was a great idea to allow both value semantics
> and pointer semantics for the same types in C++ by the simple
> addition of a * or &. What was wrong with that that needed
> to be fixed in D? GC could have been done without changing
> this. Now in D template code doesn't know which
> semantics apply and structs can't inherit. If you write
> something as a struct and then realise you need inheritance
> you're stuck. D has so many good ideas it's a shame to see
> it broken in this way...

I 99% agree with you, but I would like to debate just a smidgeon.  I 
dislike the fact that in C++ (unless you're very careful) your "structs" 
are really heavyweight classes (vtbl, etc.)  I like the fact that in D 
you can explicitly differentiate between heavyweight entities (classes) 
and lightweight ones (structs).

But I very much agree that for clarity, consistency, and template-ease, 
the syntax for "pointer/reference to a class" should be identical to the 
syntax for "pointer/reference to a struct".

So I would argue that there was something broken with C++ structs and 
classes.  D fixed it, but then broke something else. :(



More information about the Digitalmars-d mailing list