#### Archived

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

# inline functions

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

## 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 on other sites
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 on other sites
Thanx spearhawk...

##### 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 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 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 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 ]

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 14
• ### Forum Statistics

• Total Topics
632155
• Total Posts
3004477

×