Bart said:
Your argument against assigning a restricted meaning to struct is that
the compiler can't help you in enforcing that restricted meaning.
Again, you misrepresent my argument. It seems on purpose since I quite
explained it earlier.
It's too hard to track what everyone whats to use this struct keyword
for. It seems that among the various proponents for using struct only
for some something or other, but never classes, can't agree on what that
something or other is. This speaks volumes toward its utility in
expressing any one of these things.
The point of my argument is that 'struct' and 'class' mean exactly the
same thing in the C++ language. There is no inherent reason to prefer
'class' over 'struct'. The various purposes proposed range from
ill-defined to overly strict and difficult to enforce. Since you'll get
no help from the compiler, and the things you want to enforce need to be
tracked by the individual in ways that have nothing to do with 'struct'
vs. 'class', the use of these keywords to hold extra meaning seems to be
quite ill-advised.
You're taking this statement and inverting it incorrectly. Just because
THIS non-compiler enforced semantic issue is ill-advised does not mean
that ALL are. I gave quite concrete reasons why I think attempting to
force people to use 'struct' only for "non-class" objects is
questionable at best, and why those same arguments can't be applied to
code formatting and standards in general.
You say you want C compatibility, but this does not preclude not using
struct for classes.
You say you want to ensure this or that, but this does not preclude not
using struct for classes.
All the various purported reasons given so far seem to me to be better
expressed in comments. "This object needs to be C compatible," for
instance (which might also be expressed with extern "C"). The 'struct'
keyword does not seem sufficient to express what is desired in any of
these cases, nobody agrees what it should be expressing, and the use of
'struct' in modern C++ texts for objects that could certainly be viewed
as class-like in nature is quickly becoming common.
The OP stated, as point of fact, that you should never use 'struct' for
class objects and I stand utterly unconvinced so far that this is a
logical assumption. Frankly, the best argument for using 'class'
instead of struct is to force the very verbosity that the OP was
complaining about originally. I haven't seen a need to issue such a
constraint in my team.
I'm not saying that coding standards are useless (we have many), just
this one. No amount of misrepresenting of that argument will change it.