August 2001
Beginner
482 pages
10h 52m
English
Just as you can ask the compiler to make a regular function inline, you can make class methods inline. The keyword inline appears before the return value. The inline implementation of the GetWeight() function, for example, looks like this:
inline int Cat::GetWeight()
{
return itsWeight; // return the Weight data member
}
You can also put the definition of a function into the declaration of the class, which automatically makes that function inline. For example:
class Cat
{
public:
int GetWeight() const { return itsWeight; } // inline
void SetWeight(int aWeight);
};
Note the syntax of the GetWeight() definition. The body of the inline function begins immediately after the declaration of the class method; there is no semicolon ...
Read now
Unlock full access