 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sun Sep 24, 2006 9:10 am Post subject: why did c++ add the class keyword? |
|
|
The class keyword created a lot of confusion that resulted in a popular
style that says struct is appropriate for POD (plain old data) and
class is appropriate for fancier things (member functions, data hiding,
inheritance). And indeed the FAQ even advocates this usage model. I
myself have broken from this tradition because I find the public
defaulting of struct more appropriate than class and thus prefer it
100% of the time. The benefit is I no longer need to unhide the
constructor and I don't lose any explicit control over privacy. So what
was the reason for introducing the class keyword? |
|
| Back to top |
|
 |
Steve Pope Guest
|
Posted: Sun Sep 24, 2006 9:10 am Post subject: Re: why did c++ add the class keyword? |
|
|
<440gtx (AT) email (DOT) com> wrote:
| Quote: | The class keyword created a lot of confusion that resulted in a popular
style that says struct is appropriate for POD (plain old data) and
class is appropriate for fancier things (member functions, data hiding,
inheritance). And indeed the FAQ even advocates this usage model. I
myself have broken from this tradition because I find the public
defaulting of struct more appropriate than class and thus prefer it
100% of the time.
|
(OT)
I also always use struct, since normally the first element of
a struct or class is public, and therefore it saves a keyword.
I find the theory that if there's so much as a member function it
should be a class unconvincing. Everyone knows a struct
and a class are the same thing.
But please note I am not a software engineer in the first place. :-)
Steve |
|
| Back to top |
|
 |
Thomas Matthews Guest
|
Posted: Sun Sep 24, 2006 9:10 am Post subject: Re: why did c++ add the class keyword? |
|
|
440gtx (AT) email (DOT) com wrote:
| Quote: | The class keyword created a lot of confusion that resulted in a popular
style that says struct is appropriate for POD (plain old data) and
class is appropriate for fancier things (member functions, data hiding,
inheritance). And indeed the FAQ even advocates this usage model. I
myself have broken from this tradition because I find the public
defaulting of struct more appropriate than class and thus prefer it
100% of the time. The benefit is I no longer need to unhide the
constructor and I don't lose any explicit control over privacy. So what
was the reason for introducing the class keyword?
|
Most of the time, I use the class keyword and
annotate the sections. I have sections for public,
protected and private in my stencil. The class
keyword helps me to distinguish object-oriented
projects from ad-hoc or C style projects.
My philosophy is that everything should be private
unless proven otherwise. Information is distributed
on a need to know basis (high encapsulation). This
really helps in debugging, especially on large
projects.
For demos and experiments, I use the struct.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|