Here is the sample code. I have a function print without definition and I used it in the print_in_A() in the struct A.
Why can this code compile and run?
void print(int x);
struct A {
void print_in_A() {
print(1);
}
};
int main()
{
A a;
return 0;
}
And also, if I define an inline function like this, it can compile and run too. But if I remove the inline keyword, it fails to compile.
void print(int x);
inline void print_int(int a) {
print(a);
}
int main()
{
return 0;
}
DEMO - Without error when inline is used
DEMO - With error when inline is not used
Can anyone tell me why?