我读ODR并作为规则说"In the entire program, an object or non-inline function cannot have more than one definition"
,我尝试了以下多重定义...一个定义规则 - 内联函数
file1.cpp
#include <iostream>
using namespace std;
inline int func1(void){ return 5; }
inline int func2(void){ return 6; }
inline int func3(void){ return 7; }
int sum(void);
int main(int argc, char *argv[])
{
cout << func1() << endl;
cout << func2() << endl;
cout << func3() << endl;
cout << sum() << endl;
return 0;
}
file2.cpp
inline int func1(void) { return 5; }
inline int func2(void) { return 6; }
inline int func3(void) { return 7; }
int sum(void) { return func1() + func2() + func3(); }
它的工作原则如下。我可以有多个内联函数的定义。
- 非内联函数链接和内联函数链接有什么区别?
- 链接器如何区分这两者?
他引用的内容表示一个对象或*非内联函数不能有多个定义。 –