Inheritance

I created two classes, Board_t and Peg_t
Peg_t Inherits all the private members from Board_t.
Now I am trying to use the private member in Board_t in Peg_t, but I am receiving the error that it is inaccessible.
Here's the relevant part of the code:
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
class Board_t
{
private:
	char board[9];
public:
	void SetBoard();
	void PrintBoard();
};
//.......
class Peg_t: private Board_t
{
	bool UserControl;
public:
	Peg_t (bool UserController);
	char Peg;
	void VictoryCheck();
	void DefeatCheck();
	void Move();
};
//........
void Peg_t::VictoryCheck()
{
	if (UserControl = true)
	{
		if (board[0])

	}

}


Error if in Line 25
Last edited on
You can't access private members of a base class. If you want to do this, use protected.

Btw, this is an assignment: if (UserControl = true)
You meant if (UserControl)
Last edited on
So what's the point of having Private inheritance?
And thanks for that correction and explanation!
Actually, that wasn't true, so no worries.
closed account (z05DSL3A)
So what's the point of having Private inheritance?

Private inheritance represents an has-a relationship between classes.

a Peg_t has a Board_t does not seem to be the correct thing to do hear anyway.
Topic archived. No new replies allowed.