Does the function definition inside the header always define so that the compiler treats it as inline?

I just found out that defining a C ++ function inside a class header file makes an inline function. But I know that placing the inline keyword next to a function is just a suggestion, and the compiler will not necessarily follow it. This is the same for the headers defined by C ++ functions, and is there a difference in behavior between the stand-alone C ++ function and the C ++ function that is part of the class?

+5
source share
4 answers

"defining a C ++ function inside the class header file makes the inline function"

. ( ) . " inline" , inline. , , .

, foo . bar :

struct Foo {
    void foo() {}
    void bar();
};

void Foo::bar() {}

" inline - , "

inline . - , . . "" , .

, , , , , , , . , , , bar . bar, .

, inline ++ , , , . , , inline. , , gcc , , ( ), .

cpp -. , , #include , cpp , - . , , -. , , , . " " " cpp, , ".

+15

++ , , , , . , ; .

+3

, . , inline, , , , . , , .

, , . , (, , ) , inline , .

+1

, .cpp, ( ). .

, , , , .

0
source

All Articles