Original Post
🔒 Locked
inline functions
Advertisement
The inline keywoard does exactly what it says it does, inlines.
e.g:
It''ll be a tad faster in that that it eliminates the function call (very smal amount of time, but can be important if called offten). The bad thing with it is that the code gets longer, e.g bigger exes.
e.g:
inline void PrintHello()
{
cout << "Hello" << endl;
}
int main()
{
PrintHello();
}
// Becomes when compiling
int main()
{
cout << "Hello" << endl;
}
It''ll be a tad faster in that that it eliminates the function call (very smal amount of time, but can be important if called offten). The bad thing with it is that the code gets longer, e.g bigger exes.
It''s basically the C++ version of a C macro, meaning that it ideally incurs no function call overhead (that is, its text is pasted into the calling code, if the compiler does inline it), but with considerable improvements: Type safety, for one thing, and for another, it''s a real function, so you can do things like recursion (though your compiler might not inline a recursive function - it makes sense only if it can deduce the recursion depth at compile time, and it is not too great) and taking its address.
But remember, the inline keyword is a hint, not a request. The compiler can choose not to inline the function if it doesn''t want to.
I don''t have a signature
I don''t have a signature
quote:
Original post by _elmo
Sometimes the inline function is used in classes... Will this means that the whole class is placed where the function is called???
No, still only the member function. And anyway, you *already* have an instance of the class (in your case aclass).
Also, know that member functions fully defined in the body of the class (i.e. with the code for the function written within the class itself), are implicitely declared inline. The keyword is redundant.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement