Jump to content

Recommended Posts

Posted

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;

}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.