Jump to content
• Advertisement

Archived

This topic is now archived and is closed to further replies.

inline functions

This topic is 5593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know where to use the inline keyword, but what is the meaning of an inline function...? Makes this the function faster or does it take less memory...? Please can anyone tell me the meaning of the inline keyword, and when to use it...?! Thanx... _elmo nieuwe schoenen...

Share this post

Share on other sites
Advertisement
The inline keywoard does exactly what it says it does, inlines.
e.g:

inline void PrintHello(){   cout << "Hello" << endl;}int main(){   PrintHello();}// Becomes when compilingint 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.

Share this post

Share on other sites
Thanx spearhawk...

Share this post

Share on other sites
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.

Share this post

Share on other sites
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

Share this post

Share on other sites
Sometimes the inline function is used in classes... Will this means that the whole class is placed where the function is called???

class AClass {
...
public:
inline void doSomething() {
i++;
}
};

int main(void) {
AClass *aclass = new AClass();

aclass->doSomething();

return 0;
}

Share this post

Share on other sites
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 ]

Share this post

Share on other sites

• Advertisement

Announcements

• Advertisement

• Popular Now

• 10
• 17
• 9
• 14
• 41
• Advertisement
• Forum Statistics

• Total Topics
631067
• Total Posts
2997740
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!