static vs inline for functions implemented in header files

后端 未结 4 1137
心在旅途
心在旅途 2021-02-01 18:20

The way I think of inline in C++ is for linkage/scoping. I put it in the same basket with extern and static for global objects.

Ty

4条回答
  •  走了就别回头了
    2021-02-01 19:12

    The main difference is what happens with any static locals in the function -- if the function is static then each compilation unit will have its own copy of the static locals distinct from any other compilation unit. If the function is inline, there will only be one (set of) static local(s) shared by all compilation units.

提交回复
热议问题