|
|||||||||||||||||||
|
Section 9:
|
[9.8] Is there another way to tell the compiler to make a member function inline?
Yep: define the member function in the class body itself:
class Fred {
public:
void f(int i, char c)
{
...
}
};
Although this is easier on the person who writes the class, it's harder on all
the readers since it mixes "what" a class does with "how" it does them.
Because of this mixture, we normally prefer to define member functions
outside the class body with the inline
keyword. The insight that makes sense of this: in a reuse-oriented
world, there will usually be many people who use your class, but there is only
one person who builds it (yourself); therefore you should do things that favor
the many rather than the few. This approach is further exploited in
the next FAQ.
|
||||||||||||||||||