On 5/15/07, Jim Dougherty <[EMAIL PROTECTED]> wrote:
> I am a long time C programmer who is currently trying to teach himself C++
> and I
> just ran into the concept of Inline functions and I have a question. From the
> callers point of view (or from any point of view for that matter) how is an
> Inline function any better/worse/different than a macro with arguments? What
> are some reasons to write/use Inline functions as opposed to macros and vice
> versa?
>
> inline double inches_to_feet(double inches) { return(inches/12.0); }
>
> #define INCHES_TO_FEET(inches) ((inches)/12.0))
The biggest difference? No type checking with a macro. Inline
functions can also be used for methods of a class, which you certainly
can't do with macros. There's very little reason to use pre-processor
macros in C++, IMHO, since you can use const, enum and inline
functions and the code is cleaner and more consistent.
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi