GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  Inline Function Advantages

Answer: What are the advantages of inline functions over macros?


April 04, 2009 11:19:02 #3
 dipuprits   Member Since: April 2009    Total Comments: 3 

RE: Inline Function Advantages
 

To add to the above points, Inline functions can be overloaded but Macros
cannot be overloaded.


Ex:

#define MYMAC(p) if(p) cout << "single pointer valid" << endl;

#define MYMAC(p,h) if(h==1) cout << "pinter and H valid" << endl;


The second version replaces the macro. So a call to MYMAC(ptr) where ptr is
some pointer, you get warnings that not enough arguments for the macro which is
because the second version has replaced the MYMAC definition.


     

 

Back To Question