What is the difference between an inline member function and a normal member function?

Is there any difference between a built-in member function (body inline function) and another normal member function (function body in a separate .cpp file)?

eg,

class A
{
  void member(){}
};

and

// Header file (.hpp)

class B
{
  void member();
};

// Implementation file (.cpp)

void B::member(){}
+3
source share
4 answers

There is no difference.

The only difference between the two is that the member inside the class is implicitly marked as inline . But that makes no real difference.

See: built-in and efficient methods

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

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

: inlined. , , . , , .

+7

inline , .

B , .

A # -. , / - .

B B.cpp, /. , , , .

/ "" "" (, Windows dllimport/dllexport, GNU (visibility = "default" ))

+3
+2

, , class B .

For example, it B.cppmay include header files that it B.hppdoes not have, which can significantly affect the build process for large projects.

But even without a separate translation unit, you can sometimes have a cyclical dependency, which is resolved by separating the definitions. For example, a function can take a type parameter that was previously declared before B was defined, and then determined by the time that the function was defined. If this type uses the definition of B in its own definition, it cannot simply be defined before B.

+1
source

Source: https://habr.com/ru/post/1784739/


All Articles