Re: Classes vs Structs?
On Jun 7, 1:19 pm, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
Gennaro Prota wrote:
On Thu, 07 Jun 2007 09:55:14 +0100, Zeppe wrote:
no, it's not an error. Stroustrup doesn't say that you _need_ to create
a class. He says that you can solve that problem creating a class.
Actually, you can solve it also declaring the members private in a
struct. It's deprecated, anyway, such a use of the struct keyword.
In what language?
C++, what else? Just saying that defining classes with the struct
keyword is considered deprecated, and that usually the struct keyword is
used mostly for simple data structures. It's not formally deprecated,
but it's a bad habit, such as using macros and stuff like that.
It's a bad habit according to who? I've seen many different
conventions in this regard---I generally use struct if the data
members are public, and class if they are private (and they are
always all one or all the other), regardless of the presence or
absence of constructors, member functions, etc. But that's just
one convention. Two others I've seen are 1) struct means it's
strictly compatible with C, otherwise, use class, and 2) struct
is used whenever all of the members are public, even if there
aren't any data members (in which case, I use class). From what
I've seen, I think that Stroustrup uses this last convention,
which means that many functional objects for the STL are
declared using struct. Are you saying that Stroustrup has bad
habits?
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34