[c++] Inline Function
2017-03-12 22:03
302 查看
The inline functions are a C++ enhancement feature to increase the execution time of a program. Compiler replace the definition at compile time instead of referring function defination at runtime.
NOTE - This is a suggestion to compiler to make the function inline. If function is big(in term of instruction etc), compiler can ignore the "inline" request and treat it as normal function.
To make an function as inline, start the defination with the keyword "inline"
It is just a suggestion, not compulsion. Compiler may or may not inline functions you marked as inline. It may also decide to inline functions not marked as inline at compilation or linking time.
All the member functions declared and defined within class are inline by default. So no need to define explictly.
Reference:
What is C++ inline functions, cplusplus.com
NOTE - This is a suggestion to compiler to make the function inline. If function is big(in term of instruction etc), compiler can ignore the "inline" request and treat it as normal function.
To make an function as inline, start the defination with the keyword "inline"
Class A{ public: inline int add(int a, int b){ return (a + b); } }; Class B{ public: int add(int a, int b); }; inline int B::add(int a, int b){ return (a + b): }
It is just a suggestion, not compulsion. Compiler may or may not inline functions you marked as inline. It may also decide to inline functions not marked as inline at compilation or linking time.
All the member functions declared and defined within class are inline by default. So no need to define explictly.
Reference:
What is C++ inline functions, cplusplus.com
相关文章推荐
- C/C++: Inline function, calloc vs malloc
- C/C++: Inline function, calloc vs malloc
- C/C++: Inline function, calloc vs malloc
- C/C++: Inline function, calloc vs malloc
- C++内置函数(inline function)概念
- C/C++: Inline function, calloc vs malloc
- C++ inline function
- C/C++: Inline function, calloc 对比 malloc
- C/C++: Inline function, calloc vs malloc
- [C++] inline function
- C++ inline function
- Using Inline Assembly in C/C++
- [C++]Call virtual member function in constructor or destructor
- Discuz7.2 BUG :"Warning: sprintf() [function.sprintf]: Too few arguments in xxxxxxxx/include/discuzcode.func.php on line 369"
- Question 20: Which allocator member function do standard containers use to acquire storage for their elements in C++?
- Question 16: Which of the following methods can a developer use to override the default terminate() function in C++?
- 内联函数 Inline Function
- Drupal 6.1.0 Deprecated: Function ereg() is deprecated in xxx includes/file.inc on line 902?
- Visual C++ Inline Assembly 简介
- An Inline Function is As Fast As a Macro -- Using GCC