+skyler_sdf Posted June 24, 2012 Report Posted June 24, 2012 Clasele friend au acces nu doar la datele si metodele private, ci si la metodele clasei. NU reprezinta un exemplu de mostenire. Metodele din clasa de baza nu devin metode si pentru clasa declarata friend. //using a friend class #include<iostream> using namespace std; class TwoValues{ int a; int b; public: TwoValues(int i, int j){ a=i; b=j;} friend class Min; }; class Min{ public: int min(TwoValues x); }; int Min::min(TwoValues x) { return x.a <x.b ? x.a : x.b; //i.e. if(x.a<x.b) return x.a; else return x.b; } int main() { TwoValues ob(10, 20); Min m; cout<<m.min(ob); system("PAUSE"); return 0; }
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now