Is the member function defined in the class definition be automatically as an inline function? Or explicitly add Inline keywords when defining member functions, which will be defined into inline? Actually not! For compilers, the inline function is a request, not a guarantee (C Primer (3ed) P26). The following is taken as an example of code generated under VC 7.0. // Inline inline function demonstration // inlinedemo.h
#pragma overce
#include
Using namespace std;
Class inline {public: // inline? Inline () {cout << "inline construct!" << endl;
// inline? Void setab (int A, int b) {this-> a = a; this-> b = b;} int GETA (); int Getb (); protected: int A, b;};
// inline? inline int inline :: geta () {return a;}
// Non-inline? int inline :: getb () {return b;}
// inlineDemo.cpp: Define the entry point of the console application. //
#include "stdafx.h" #include "inlineDemo.h"
INT _TMAIN (int Argc, _tchar * argv []) {inline inlinea;
Inlinea.seTab (10, 12);
COUT << inlinea.geta () << endl;
Cout << inlinea.getb () << endl;
Return 0;}
Option / 0B1 ("Online Function Expand" only suitable for __inline ") open anti-assessment code: .text: 004012d0 _main proc near; code xref: j__mainj.text: 004012d0.text: 004012d0 var_58 = DWORD PTR -58h.text: 004012D0 var_40 = dword ptr -40h.text: 004012D0 var_28 = dword ptr -28h.text: 004012D0 var_C = dword ptr -0Ch.text: 004012D0 var_8 = dword ptr -8.text: 004012D0.text: 004012D0 push ebp.text: 004012D1 mov ebp, esp.text: 004012D3 sub esp, 58h.text: 004012D6 push edi.text: 004012D7 lea edi, [ebp var_58] .text: 004012DA mov ecx, 16h.text: 004012DF mov eax , 0CCCCCCCCh.text: 004012E4 rep stosd.text: 004012E6 push offset ?? _ C @ _0BC @ FJCDLOJM @ inLine 5Construct $ CB $ AA @; "inLine Construct!" is compiled into .text inline:??? 004012EB push offset STD__cout.text: 004012f0 Call J _? $? 6u? $ char_traits @ d @STD @@@st D @@ yaAAV? $ BASIC_OSTREAM @ du? $ char_traits @ D @ std @@@ 0 @ aav10 @ Pbd @ z.text: 004012f5 add esp, 8.Text: 004012F8 MOV [EBP VAR_28], EAX.TEXT: 004012FB Push 0ah.text: 004012FD MOV ECX, [EBP VAR_28] .TEXT: 00401300 CALL J_ PUT @? $ basic_ostream @ du? $ char_traits @@ @@ qaeaav12 @ D @ z; std :: Basic_OStream
DU? $ Char_traits @@ @@@ std @@ qaeaav12 @ xz; std :: basic_ostream
Inline :: getB (void) is non-inline .Text: 00401346 push eax.text: 00401347 MOV ECX, OFFSET STD__COUT.TEXT: 0040134C Call J _ ?? 6? $ Basic_ostream @ du? $ Char_traits @ d @ std @@@@ STD @@ qaeaav01 @ h @ z; std :: basic_ostream
The answer to the two questions is affirmative. This option has not been opened as an anti-disassembly code: .text: 004015d0 _Main proc near; code xref: j__mainj.text: 004015d0.text: 004015d0 var_10 = DWORD PTR-10H.TEXT: 004015D0 var_c = dword PTR-0CH.TEXT: 004015D0 var_8 = dword ptr -8.text: 004015D0 var_4 = dword ptr -4.text: 004015D0.text: 004015D0 push ebp.text: 004015D1 mov ebp, esp.text: 004015D3 sub esp, 10h.text: 004015D6 mov eax, 0cccccccch.text: 004015dB MOV [EBP VAR_10], EAX.TEXT: 004015DE MOV [EBP VAR_C], EAX.TEXT: 004015E1 MOV [EBP VAR_8], EAX.TEXT: 004015E4 MOV [EBP VAR_4], EAX. Text: 004015E7 LEA ECX, [EBP VAR_C] .text: 004015EA CALL J _ ?? 0inline @@ qe @ xz; inline :: inline (void) .text: 004015ef push 0ch.text: 004015f1 push 0ah.text: 004015F3 LEA ECX, [EBP VAR_C] .TEXT: 00401 5F6 Call J_? Setab @ inline @@ qaexhh @ z; inline :: setab (int, int) .text: 004015fb push offset LOC_4010B4.TEXT: 00401600 LEA ECX, [EBP VAR_C] .TEXT: 00401603 CALL J_? Geta @ Inline @@ Qaehxz; Inline :: Geta (void) .text: 00401608 Push Eax.Text: 00401609 MOV ECX, Offset std__cout.text: 0040160E Call J _ ?? 6? $ Basic_ostream @ du? $ Char_traits @ d @ std @@ @ std @@ qEaav01 @ h @ z; std :: basic_ostream
(int) .text: 00401613 MOV ECX, Eax.Text: 00401615 Call J _ ?? 6? $ basic_ostream @ du? $ char_traits @@ @@ qaeaav01 @@ z @ z; std :: Basic_OStream