Jump to content

Forward Declaration C++


skyler_sdf

Recommended Posts

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;

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.