//Friends in multiple classes - Defining friendship in more than one class.
#include<iostream>
using namespace std;
//forward declaration of classes
class Circle;
class Square;
class Circle
{
char cColour[20];
public: Circle( char x[20])
{ strcpy(cColour,x);}
friend bool compare(Circle, Square);
};
class Square
{
char sColour[20];
public: Square( char y[20])
{ strcpy(sColour,y);}
friend bool compare(Circle, Square);
};
bool compare(Circle p, Square q)
{
int cmp;
cmp = strcmp(p.cColour,q.sColour);
if (cmp==0)
return true;
else
return false;
}
void main()
{
Circle cir("REED");
Square sqr("RED");
if (compare (cir,sqr))
cout<<"same"<<endl;
else
cout<<"diff"<<endl;
system("pause");
};
No comments:
Post a Comment