Interview Question: Inline or Define

Sample Question #299 (programming – C++)
Explain the differences between inline functions and #define in C++.
This entry was posted in Sample Qs. Bookmark the permalink.

One Response to Interview Question: Inline or Define

  1. Brett says:

    1) Inline functions are specific to a class; #define is global.
    2) Inline functions work on member variables (usually private); #define works on symbols.
    3) Inline functions are parsed by the compiler whereas #define is expanded by the precompiler.
    4) Inline functions are safer because they follow type conventions of functions; #define can be anything.
    5) Inline functions can be used for debugging; #define cannot because once it’s expanded you don’t get a break point at run time.
    6) Inline functions benefit from consistent argument treatment; #define is a wild beast in this.
    Maybe other differences?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s