I just created two file to test the inline function's linkage, the first one
#include <iostream>
using namespace std;
inline int f1(int a,int b){
a=a+b;
while(a!=0)
a--;
cout<<"inline";
return a;
}
the second one:
int main(){
extern void f1(int a,int b);
f1(1,2);
}
g++ frist.cc second.cc
undefined reference to `f1(int, int)'
linker raise a error, as i expect the inline function is default internal linkage so the result is right.
but, when I add a call function of the inline function to the first file:
#include <iostream>
using namespace std;
inline int f1(int a,int b){
a=a+b;
while(a!=0)
a--;
cout<<"inline";
return a;
}
int callf1(){
f1(10,2);
}
and compile again, it passed, and can run without error, so I want ask what had happened here?