关于函数申明顺序的一个怪问题
class Friendly
{
int i ;
public:
Friendly(int theInt):i(theInt){}
friend void f(const Friendly&);
void g(){f(*this);}
};
void h()
{
f(Friendly(1));
}
void f(const Friendly& fo)
{
cout<<fo.i<<endl;
}
int main()
{
h();
Friendly(2).g();
return 0;
}
问题:这段代码是可以运行的,那么在h()中是如何识别在他下面才定义的f()的呢?没什么没有出现f()未申明的编译错误呢?不明白,望大虾给解释一下,谢过!