Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition can appear explicitly in the program, it can be found in the standard or a user-defined library, or (when appropriate) it is implicitly defined (see 12.1, 12.4 and 12.8). An inline function shall be defined in every translation unit in which it is used.
编译器参数 inline-forceinline Specifies that an inline routine should be inlined whenever the compiler can do so.
Because C++ member functions whose definitions are included in the class declaration are considered inline functions by default, using this option will also make these member functions "forceinline" functions.
When you use this option to change the meaning of inline to "forceinline", the compiler may do so much additional inlining that it runs out of memory and terminates with an "out of memory" message.
finline-limit inline-max-per-compile [解决办法] 去看herb sutter 的《exceptional c++》系列,大概一共3论Inline 其中有足够解答楼主的信息。 herb sutter的话,可比我们这些混混权威多了。 这个问题,即使是扣标准也是解答不了的。 [解决办法] 其实我觉得标准说的挺清楚的,c++11 3.2/3 说 An inline function shall be defined in every translation unit in which it is odr-used.
所以 inline function 必然只能定义在头文件里面,因为这样才能够通过 #include 将其定义,而非仅仅是声明,包含进目标 translation unit 里面。非得写在 cpp 里面也行,但是就得像 #29 说的,#include 该 cpp 文件了,不过这样用 cpp 的话,本质上也就是将其用作 .h 文件了。#18 的例子程序中因为 main.cpp 只包含了 test.h,所以在 main 里面只能看到 test::fun 的声明,而看不见定义,因此会导致链接错误,此例子展示了 3.2/3 的意思。