Jump to content

Recommended Posts

Posted
#include<iostream>

using namespace std;

class myclass

{


	int a, b;

public:

	friend int sum(myclass x);

	void set_ab(int i, int j);

};

void myclass:: set_ab(int i, int j)

{

	a=i;

	b=j;

}

int sum(myclass x)

{


	//pentru ca sum() este "friend" pentru myclass, poate accesa direct a si b

	return x.a+x.b;

}

int main()

{


	myclass n;

	n.set_ab(4, 2);

	cout<<sum(n);

	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.