Advertisement
Emanuele_Bruno

Esempio di funzione friend

Feb 11th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. // friend functions
  2. // #include "stdafx.h" // serve per VisualStudio
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class Myclass
  8. {
  9.     int a, b;
  10. public:
  11.     Myclass (int i, int j) { a = i; b = j; }
  12.     friend int prodotto(Myclass);
  13. };
  14.  
  15. int prodotto(Myclass temp)
  16. {
  17.     return ( temp.a* temp.b );
  18. }
  19.  
  20. int main()
  21. {
  22.     Myclass A(5, 3);
  23.     cout << prodotto(A); //il risultato รจ 15
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement