#include <iostream>
usingnamespace std;
constint IDLE=0;
constint INUSE=1;
class C2; // forward declaration
class C1 {
int status; // IDLE if off, INUSE if on screen
// ...
public:
void set_status(int state);
int idle(C2 b); // now a member of C1
};
class C2 {
int status; // IDLE if off, INUSE if on screen
// ...
public:
void set_status(int state);
friendint C1::idle(C2 b); // a friend, here
};
void C1::set_status(int state)
{
status = state;
}
void C2::set_status(int state)
{
status = state;
}
// idle() is member of C1, but friend of C2.
int C1::idle(C2 b)
{
if(status || b.status) return 0; // why this line shows error ?
elsereturn 1;
}
int main()
{
C1 x;
C2 y;
x.set_status(IDLE);
y.set_status(IDLE);
if(x.idle(y)) cout << "Screen Can Be Used.\n";
else cout << "Pop-up In Use.\n";
x.set_status(INUSE);
if(x.idle(y)) cout << "Screen Can Be Used.\n";
else cout << "Pop-up In Use.\n";
getchar();
return 0;
}
if(status || b.status) return 0; // why this line shows error ?
i'm working on something that has 37 projects in the VS solution. Intellisense gets very confused :)
Basically, if there's red lines but it compiles, ignore the red lines.