I just started to write this program. Right now I have 2 main classes- class Rummikub which contains a pool of 106 tiles which I declared as a private data member- string tiles[106]. I also have another class, class Hand. Hand will need to maintain a dynamic "array" of some sort like a vector which will increase and/or decrease in size. The "hand" is the player's current hand of tiles that they have. This "Hand" class contains as private data members "vector<string> vecHand" and "vector<string>::iterator it" as the iterator.
I'm needing this string vector to be able to access the private data member of class Rummikub, which is string tiles[106]. I know I can do this by declaring a friend of the class. I'm having a hard time with this and would appreciate any feedback on how to do this, not necessarily using the "friend" idea. I'm not that familiar with "friends" so I may have totally messed that up in the code below. Anything anyone has is appreciated. Any ideas on how to accomplish this would be terrific. Below are snippets of my code. Thanks a bunch for the help!!
class Rummikub {
friend class Hand; //class Rummikub is friends with class Hand
public:
~Rummikub();
Rummikub(); //constructor sets and shuffles the tiles
string itos(int); //custom function
private:
string tiles[106];
};
class Hand {
friend class Rummikub; //class Hand is friends with class Rummikub
public:
Hand();
void checkForMoves();
void dropTile();
string accessTile();
private:
vector<string> vecHand;
vector<string>::iterator it;
};
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.