Jul 5, 2011 at 9:29am UTC
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 Jul 5, 2011 at 9:31am UTC
Jul 5, 2011 at 9:33am UTC
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 Jul 5, 2011 at 9:51am UTC
Jul 5, 2011 at 9:36am UTC
So what's the point of having Private inheritance?
And thanks for that correction and explanation!
Jul 5, 2011 at 9:53am UTC
Actually, that wasn't true, so no worries.