Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!haven.umd.edu!mimsy!prometheus!media!hqda-ai!fstc-chville.army.mil!adm!lhc!lhc!warsaw From: warsaw@nlm.nih.gov (Barry A. Warsaw) Newsgroups: comp.lang.c++ Subject: Re: Public vs Private header files in C++ Message-ID: Date: 5 Jun 91 16:19:52 GMT References: <5243@servax0.essex.ac.uk> <25231@well.sf.ca.us> Sender: usenet@nlm.nih.gov (usenet news poster) Reply-To: warsaw@nlm.nih.gov Organization: Century Computing, Inc. Lines: 54 In-Reply-To: al@well.sf.ca.us's message of 5 Jun 91 06:24:35 GMT >>>>> "Alfred" == Alfred Fontes writes: Alfred> This can be avoided to a certain extent by putting the Alfred> public members at the top of the class definition, Alfred> followed by protected and finally by private members. Alfred> This saves the user from having to look at the private Alfred> stuff. If you have inlines, they can immediately follow Alfred> the end of the class definition. This is a Really Good Suggestion. I'll second that, as this is the C++ coding style we've adopted and have been using for several months. Explicitly stating whether something is public/private/protected is also a good habit to get into, I think. And separating out inline functions also helps with header file readability. Example follows siggy. -Barry "When in doubt, cout." -------------------- cut here -------------------- // foo.h class foo { public: foo( int num ); inline int number( void ); // get inline void number( int num ); // set protected: virtual int valid( int num ); private: int priv_number; }; inline int foo::number( void ) { return( priv_number ); }; inline void foo::number( int num ) { if( valid( num )) priv_number = num; }; // foo.cc foo::foo( int num ) { ... }; // etc...