Jump to content

Recommended Posts

Posted

Este posibil sa declaram o clasa, si mai tarziu sa o detaliem... Acest lucru este posibil atata timp cat nu construim obiecte(s.a.) de tipul clasei careia ii amanam detalierea..

De ex:

#include<iostream>

using namespace std;

const int IDLE=0;

const int INSUE=1;

//forward declaration

class C2;


	class C1{

		int status; //IDLE if off, INSUE if on screen

	public:

		void set_status(int state);

		friend int idle(C1 a, C2 b);

	};

	class C2

	{

		int status; //IDLE if off, INSUE if on screen

	public:

		void set_status(int state);

		friend int idle(C1 a, C2 b);

	};


void C1::set_status(int state)

{


	status=state;

}

void C2::set_status(int state)

{


	status=state;

}

int idle(C1 a, C2 b)

{


	if(a.status || b.status)

		return 0;

	else

	return 1;


}

int main()

{

	C1 x;

	C2 y;

	x.set_status(IDLE);

	y.set_status(IDLE);


	if(idle(x, y))

		cout<<"Screen can be used.";

	else

		cout<<"in use. ";


	x.set_status(INSUE);

	if(idle(x, y))

		cout<<"screen can be used. ";

	else

		cout<<"in use";

	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.