Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Friend Function Not Working?

$
0
0
I have two classes Dealer and Players (this is a poker game). I am trying to deal the player's their cards so I have a function name DealPlayerCards(Players player[]) in Dealer class that I have declared as a friend in Player Class. But the problem is I still dont have access to Player's private members.

I get an error that says "Declaration is incompatible with void Dealer::DealPlayerCards(<Error Type> *players)
Also in my Dealer.cpp file(read below) I cant access Player's private members, they are underlined in red.

I do want to mention that the Dealer class and Player class are in their own separate header files and I have implemented the Dealer.cpp file in another file aswell, but in All files i have Included both headers.

Here are my classes, I did not include the implementation file of Dealer because the only thing that shows up on their is the red underlining. I have reduced the classes to only what im talking about.

// One separate File
#include "Player.h"
class Dealer
{
    public:
	void DealPlayerCards(Players players[]);
};

// The Other Separate File
#include "Dealer.h"
class Players
{
	private:
		friend void Dealer::DealPlayerCards(Players players[]);
};



When moving my cursor over the function I get the error I explained above.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>