有四个文件,header.h
,A.cpp
,B.cpp
,main.cpp
。
// header.h
struct test {
static inline int get();
};
Run Code Online (Sandbox Code Playgroud)
// a.cpp
#include "header.h"
int testA() { return test::get(); }
int test::get() { return 0; }
Run Code Online (Sandbox Code Playgroud)
// b.cpp
#include "header.h"
int testB() { return test::get(); }
int test::get() { return 1; }
Run Code Online (Sandbox Code Playgroud)
// main.cpp
#include <cstdio>
int testA();
int testB();
int main() {
printf("%d %d\n", testA(), testB());
}
Run Code Online (Sandbox Code Playgroud)
编译时g++ -o main A.cpp B.cpp main.cpp -O0
二进制输出两个相同的数字,而-O3
始终输出0 1 …