In general, it's not good practice; ideally, the
implementation wouldn't even be in the same file as the class
definition. (Ideally, too, we wouldn't have to declare the
private parts in the header file either.) There are a lot of
justified exceptions, however:
The most obvious is in really simple helper classes, where
there really isn't enough to justify separating both parts.
This is especially true if the helper class is defined locally,
in the source file, rather than in a header.
Another case is for friends, particularly in templates. If
I write (even in a template) friend void f( MyClass& )
, then
I have declared a non-template to be friend, and I have to
implement a separate non-template function for each
instantiation type. If I provide the inline implementation in
the class definition, however, the compiler will automatically
create the separate non-template function for each type it is
used. This is a very frequent motivation for definition
operator>>
and operator<<
in the class, as they cannot be
members; often they will be declared as friend
even if they
don't need access to private members, just so that they can be
defined this way.
Finally, if there are no other declarations of the functions or
operators, they are only visible within the class, or with ADL.
Which shouldn't be a problem, as long as the function has at
least one parameter which involves the class.