13.6 Shortcuts

I l @ ve RuBoard

So far you have used only function prototypes in the classes you've created. It is possible to define the body of the function inside the class itself. Consider the following code:

 class stack {     public:         // .... rest of class         // Push an item on the stack         void push(const int item); }; inline void stack::push(const int item) {     data[count] = item;     ++count; } 

This code can instead be written as:

 class stack {     public:         // .... rest of class         // Push an item on the stack         void push(const int item) {             data[count] = item;             ++count;         } }; 

The inline directive is not required in the second case since all functions declared inside a class are automatically declared inline.

I l @ ve RuBoard


Practical C++ Programming
Practical C Programming, 3rd Edition
ISBN: 1565923065
EAN: 2147483647
Year: 2003
Pages: 364

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net