noInClassMemberDefinition
Flags member functions whose body is written inside the class definition.
Member functions are declared in the class and defined outside of it, also
for classes that live only in a .cpp file.
class Box {
public:
Box() {} // Bad — flagged.
double volume() const { return _v; } // Bad — flagged.
Box(const Box &) = default; // Good.
Box &operator=(Box &&) = delete; // Good.
virtual void draw() = 0; // Good.
void resize(double factor); // Good.
};
void Box::resize(double factor) { _v *= factor; } // Good.
Constructors, destructors, operators, conversion functions, static members
and member function templates are all checked, in classes, structs, unions,
nested classes and class templates. Templates are not exempt: their members
can still be defined after the class in the same header or in an included
.tpp file.
Not flagged:
declarations, pure virtual (
= 0),= defaultand= deletemembers;members generated by a macro, e.g.
MSTD_ENUMor GTest’sTEST/TEST_F;members of local classes (declared inside a function body) and of unnamed classes, which C++ does not allow to be defined outside the class;
in-class
friendfunction definitions (hidden friends) and lambdas, which are not member functions.
Configuration
This check takes no configuration.
Disabling
[cpp]
ast_check_disabled_ids = ["noInClassMemberDefinition"]