problem

guys whats the problem with the bool function line 26 ? is something wrong with my friending ?

( Error (active) E0265 26 member "square::side" (declared at line 5) is inaccessible
)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
using namespace std;
class square  
{
	int side;
public :
	square(int side = 1) { side = side; }
	int area() { return side * side; }
	friend void Sset(square , int);
	friend bool CP(square, rectangle);
};
class rectangle 
{
	int wid, leng;
public :
	rectangle(int wid = 1, int leng = 1) { wid = wid; leng = leng; }
	int area() { return wid * leng; }
	int perimetere() { return (wid * leng) * 0.5; }
	friend void Rset(rectangle , int , int );
	friend bool CP(square , rectangle);
};
void Rset(rectangle R,int x, int y) { R.wid = x; R.leng = y; }
void Sset(square S, int x) { S.side = x; }

bool CP(square S , rectangle R ) {
	if (S.side == R.wid && S.side == R.leng) {return true;} else { return false; }
}

int main()
{
	int x, y; cin >> x >> y;
	rectangle R;
	Rset(R ,x, y);
	cin >> x;
	square S;
	Sset(S, x);
	cout << CP(S, R);

}
Last edited on
You need a forward declaration for rectangle.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
class rectangle; // for your first friend...
class square  
{
	int side;
public :
	square(int side = 1) { side = side; }
	int area() { return side * side; }
	friend void Sset(square , int);
	friend bool CP(square, rectangle);
};
class rectangle 
{
	int wid, leng;
public :
	rectangle(int wid = 1, int leng = 1) { wid = wid; leng = leng; }
	int area() { return wid * leng; }
	int perimetere() { return (wid * leng) * 0.5; }
	friend void Rset(rectangle , int , int );
	friend bool CP(square , rectangle);
};
void Rset(rectangle R,int x, int y) { R.wid = x; R.leng = y; }
void Sset(square S, int x) { S.side = x; }

bool CP(square S , rectangle R ) {
	if (S.side == R.wid && S.side == R.leng) {return true;} else { return false; }
}

int main()
{
	int x, y; cin >> x >> y;
	rectangle R;
	Rset(R ,x, y);
	cin >> x;
	square S;
	Sset(S, x);
	cout << CP(S, R);

}
ty : )
Topic archived. No new replies allowed.