If uncheck inline box when adding function to a class, only the function protoype is needed in the classname.h?
Can anybody help me to clear this thing out? I use Add Member Function Winzard to add a function to class. If I uncheck Inline box, there is only function prototype like below appear on classname.h file:
CBox operator+(const CBox& aBox) ;
and on the classname.cpp file, there is the full function:
CBox CBox::operator+(const CBox& aBox) {
return C开发者_运维问答Box();
}
However, if I check the Inline box, the full function appear on classname.h file like below:
CBox operator+(const CBox& aBox)
{
return CBox();
}
AND nothing appear on the classname.cpp.
I am not sure whether it is because of the Inline check or not? Anyway, is this a big difference between using Inline and not Inline function that I need to worry?
Another thing is that if I check Inline box, the function is CBox operator+...... But if I uncheck Inline box, the function is CBox Cbox::operator+. What is the different meaning?
Thank you very much.
If you want your function to be inlined, then, the compiler needs to be aware of it. Thus, you have to put it in the header file.
Note that most recent compilers can automatically inline function when it's needed if you switch on optimizations.
When you select in-line, it means that the code will be dropped in at the location that is being called. For this reason, the entire implementation needs to be in the header file. If you don't select inline, it will be placed in the cpp file, as one (and only one) copy should be compiled and linked.
Inlining code may make your application larger, but is considered faster has there is no overhead of a procedural call. Use inlining if the implementation is small.
精彩评论