#include <iostream> using namespace std; class Integer{ int n; public: Integer(int x = 0){ n = x; }; friend int sum(Integer& a, Integer &b); friend class Operation; }; int sum(Integer &a, Integer &b) { return a.n + b.n; } class Operation { public: int sum(Integer &a, Integer &b){ return a.n + b.n; } int dif(Integer &a, Integer &b){ return a.n - b.n; } int product(Integer &a, Integer &b){ return a.n *b.n; } int ratio(Integer &a, Integer &b){ return a.n/ b.n; } }; void main() { Integer i(100), j(2); Operation z; cout << sum(i, j); cout << z.sum(i, j) << endl; cout << z.dif(i, j) << endl; cout << z.product(i, j) << endl; cout << z.ratio(i, j) << endl; getchar(); }
友员函数
最新推荐文章于 2020-02-14 21:29:11 发布