TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
 
C++ Coding Standard
Search

Category: Class Interface

Synopsis:Public Interface of Classes


Description:
This chapter concerns the public interface of classes. The class interface is the most important part of the class. It is the contract to be used by the clients of the class.

Coding Rules

NameCheckedSynopsis
INT#001 Checked automatically with code checker Non-copy-constructors that can be called with one argument shall be declared as explicit
INT#002 Checked automatically with code checker Declare non-constant data members private
INT#003 Only declare public or protected accessors for data members that must be accessible
INT#004 Checked automatically with code checker Always specify the return type of a method/function explicitly
INT#005 Do not change the formal parameters order, just to be able to have parameter defaults
INT#006 Checked automatically with code checker A member function that should not change the state of the object shall be declared const
INT#007 If the behavior of an object is dependent on data outside the object, this data is not to be modified by const methods
INT#008 Checked automatically with code checker Use constant references (const &) instead of call-by-value, unless using a basic data type, a simple object or a pointer
INT#009 Do not use special values for don't care parameters
INT#010 Use operator overloading sparingly and in a uniform manner
INT#011 Checked automatically with code checker If you overload one of a closely related set of operators, then you should overload the whole set and preserve the same invariants that exist for built-in types
INT#012 Checked automatically with code checker Avoid multiple definition of overloaded methods/functions in conjunction with the instantiation of a class template
INT#013 Checked automatically with code checker Avoid methods and functions with many arguments
INT#014 Use a parameter of pointer type if the function stores the address or passes it to a function that does
INT#015 All variants of an overloaded member function shall be used for the same purpose and have similar behavior
INT#016 Checked automatically with code checker Make simple functions inline
INT#017 Checked automatically with code checker Do not use conversion member functions or user-defined cast operators
INT#018 Checked automatically with code checker Pass arguments of built-in types by value unless the function should modify them
INT#019 Checked automatically with code checker Once a default parameter value is defined, the value may never be changed
INT#020 Checked automatically with code checker Pass arguments of non-simple types by reference or pointer
INT#021 Checked automatically with code checker Pass arguments of class types by reference if the class is meant as a public base class
INT#022 Checked automatically with code checker A pointer or reference parameter should be declared const if the function does not change the object bound to it
INT#023 Checked automatically with code checker The copy constructor and the copy assignment operator shall always have a const reference as a parameter
INT#024 A member function that gives non-const access to the representation of an object must not be declared const
INT#025 Do not let const member functions change the state of the program
INT#026 Checked automatically with code checker In a derived class, if you need to override one of a set of the base class's overloaded virtual member functions, then you must override the whole set, or use using-declarations to bring all of the functions in the base class into the scope of the derived class
INT#027 Checked automatically with code checker If you override one of the base class's virtual functions, then you shall use the "override" keyword
INT#028 Checked automatically with code checker Supply default arguments with the function's declaration, not with the function's definition
INT#029 Use built-in boolean type where possible
INT#030 Checked automatically with code checker Do not misuse a pointer when an array is requested