Friend Function

// friendfuntion.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


//class frdfun
//{
// int a, b;
//public:
// friend int sum(frdfun Fobj);
// void set_ab(int i , int j)
// {
// a= i;
// b= j;
// }
//};
//int sum(frdfun Fobj)
//{
// return Fobj.a + Fobj.b;
//}


#define IDEL 0
#define IDINUSE 1
class B;
class A
{
int status;
public:
friend int idel(A a1 , B b1);
void set_staus(int state)
{
status = state;
}
};
class B
{
int status;
public:
friend int idel(A a1 , B b1);
void set_staus(int state)
{
status = state;
}
};
int idel(A a1 , B b1)
{
if( a1.status || b1.status ) return 0;
else return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
/*frdfun obj;
obj.set_ab(10,20);
std::cout << sum(obj);*/
A a;
B b;
a.set_staus(IDEL);
b.set_staus(IDEL);
if(idel(a,b))
std::cout << "Ready to use";
else
std::cout << "In USE";


return 0;
}

Comments

Popular posts from this blog

Smart Pointers in C++ and How to Use Them

Operator Overloading in C++

How would you read in a string of unknown length without risking buffer overflow