Q:

how does the inline function work in C++? 

now I have 2 c++ source files: test9.cpp test10.cpp, they both have a inline function with the same name. 
test9.cpp:
1 #include <iostream>
2 using namespace std;
3 void test();
4 inline void f1()
5 {
6     cout << "inline f1 in test9.cpp" << endl;
7 }   
8 int main()
9 {
10     f1();
11     test();
12     return 0;
13 } 

test10.cpp:
1 #include <iostream>
2 using namespace std;
3 inline void f1()
4 {
5     cout << "inline f1 in test10.cpp" << endl;
6 }   
7 void test()
8 {
9     f1();
10 } 

now compile them with g++:   g++ test9.cpp test10.cpp    ./a.out   I get the following result:
inline f1 in test9.cpp
inline f1 in test9.cpp

what's wrong?  I thought it would be: "inline f1 in test9.cpp inline f1 in test10.cpp"
who can tell me why?  how does the g++ compiler treats the inline function? 

A:

While the compiler will allow you (nay, require you!)  to redefine functions marked inline, the default of external linkage still applies, so you are breaking the One Definition Rule.  This results in undefined behaviour and the outcome that you are seeing. 

[C++11: 7.1.2/4]: An inline function shall be defined in every translation unit in which it is odr-used and shall have exactly the same definition in every case (3.2). [..]