c++ - How to organize a class's member functions? -
i put 'sets' after constructors because related object setup. split gets (put gets in inquires) , sets not sure if or not. best practice organizing member functions?
how that?
class foo { // friends go here if has friend ...; friend ...; // first public, protected , private public: // enums enum {...} // type defines. typedef ...; ... // destructor , constructors ~foo(); foo(...); foo(...); ... // sets. void seta(...); void setb(...); void setc(...); ... // inquiries (including gets). a() const; b b() const; ... // operators. void operator()(...); ... // operations. void dosomething(); ... protected: private: };
it's hard judge, it's personal preference or company coding standard. looking @ code, few things may not agree:
- your declarations not ordered
pubilc
,'protected` private friend
declaration has same effort when declare them in private area well. put them in private section, gives less noise inpublic section
.
below declaration order use:
use specified order of declarations within class: public
: before private
:, methods before data members (variables), etc.
class definition should start public
: section, followed protected
: section , private
: section. if of these sections empty, omit them.
within each section, declarations should in following order:
typedefs , enums constants (static const data members) constructors destructor methods, including static methods data members (except static const data members)
friend declarations should in private section, , disabled copy constructor
, other operators `should @ end of private: section. should last thing in class.
Comments
Post a Comment