Solved

difference between macro, inline and Template

Posted on 2004-09-09
5
787 Views
Last Modified: 2008-02-01
Hi
What the difference between Macro and Inline.Which one has to use when?
What is the difference  of Macro and Template?
What is the difference between Inline and Template?
Plesase tell me with some example.
Regards
Gaurav
0
Comment
Question by:nclgaurav
5 Comments
 
LVL 30

Expert Comment

by:Axter
Comment Utility
nclgaurav,
I see that you have open questions that have been abandon.

Please close your questions by awarding points, or requesting deletion of the question.

You also have the following negative feedback:
**************************************************************************
This Member has failed to responded to Expert comments, has ignored cleanup notices, and has abandoned this question.
nclgaurav,
To avoid negative feedback in the future, please read this carefully: http:help.jsp#hs5
**************************************************************************


Experts will be hesitate to help you if they see that you fail to clean up your questions, or fail to provide proper grading.

Also, please read the guide lines for assigning points to a question.
0
 
LVL 2

Expert Comment

by:guntherothk
Comment Utility
Thanks for letting the experts know axter. The experts exchange is a community. It's not free help. Users who don't want to contribute at least by closing their questions should find another place to go for help.
0
 
LVL 30

Expert Comment

by:Axter
Comment Utility
nclgaurav,
At first glance it looks like you have a good grading history, but after looking at the graded questions, it shows that you have only graded 4 questions that have points assigned.
All the other graded questions have either zero points assigned, or have been force accepted by a moderator and given an A grade.

Looking at the 4 questions you graded, you have the following grading history:
CBAB

That's very poor, considering all the questions only have 50 points, and the experts gave you more  then 50 points worth.

Experts will hesitate to help a questioner that gives poor grades.

This question is not a 50 point question.  However, many experts will still give a good detailed answer to a 50 point question if the questioner has a good grading history.

If you can not spend a little time cleaning up your open questions, then experts are not going to waste time helping you in your new questions.
0
 

Author Comment

by:nclgaurav
Comment Utility
thats fine Dear experts.From nowonwards, I will close my ask questions.For my past history, I can't do anything except saying sorry.
Regards
0
 
LVL 4

Accepted Solution

by:
pankajtiwary earned 50 total points
Comment Utility
Q: What the difference between Macro and Inline.Which one has to use when?
A: A macro is a function like entity which gets substituted with the actual code at the time of preprossing. The basic problem is since the compiler doesn't see any macros but just the substituted text so it has no idea of where the substituted text come from. Since it is normal substitution, no type chacking is done. This is fast but dangerous. C++ almost advices not to use it.
An inline is actually a normal funation whose code is actually substituted in the place where the function is called. The inline functions are superior to macros in the sense at the time of compilation, the parameters and the return type are checked everytime the function is getting called inside the source code. But here again its just the substitution of code but at the compiler level.

Q: What is the difference  of Macro and Template?
A: A macro is as defined above where as a template is a construct used in C++ for generic programming. A template can be used for generic class and functions. Anywhere the function with some type is called or a class with the possible type is made, the compiler generated the code for that particular function/class. Here also a proper type checking is done and the code is generated for all the possible calls.

Q: What is the difference between Inline and Template?
A: Inline is only used for functions whereas a template may be a class or a function. Don't confuse between inline and a template. Both are totally different beasts. You can take an inline as not a function call but substitution of function code at the desired places. A template, on the other hand, is just a skeleton defined by you on the basis of which the code for the appropriate type may be generated.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now