#include <iostream.h> class B; class A { public: A(int i) { a=i; } friend int F(A &f1,B &f2); private: int a; }; class B { public: B(int i) { b=i; }// (后续代码在右侧栏) | friend int F(A &f1,B &f2); private: int b; }; int F(A &f1,B &f2) { return (f1.a+f2.b)* (f1.a-f2.b); } void main() { A n1(10); B n2(8); cout<<F(n1,n2)<<endl; } |
阅读上面的程序,简答以下4个问题:
① 写出程序的运行结果。
② 该程序中共有几个对象,分别属于哪个类? 为什么在程序的开头处通过语句class B; 对类B进行声明?
③ 程序中的哪两条语句会分别调用A、B的构造函数?写出这两个构造函数。
④ 函数F是什么函数?它的作用是什么?
