Need help with friend functions of two classes

This code is supposed to define a function that changes the total member of the PatientAccount class using information from the Surgery class. The problem is that when I define it in the main.cpp file I get an error saying the total member PatientAccount is inaccessible. I've looked up other code and I'm doing it the same way I've seen other people do it.

Here's the code. All of this is in the main.cpp file.

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
class PatientAccount
{
private:
	float total;
	int days;

public:
	PatientAccount();
	void getDays(int);
	float printTotal();
	friend void updateTotal(PatientAccount &, Surgery, int);
};

class Surgery
{
private:
	float tonsillectomy;
	float foot;
	float knee;
	float shoulder;
	float appendectomy;

public:
	Surgery();
	float getPrice(int);
	friend void updateTotal(PatientAccount &, Surgery, int);
};

void updateTotal(PatientAccount &pat, Surgery s, int sur)
{
	if(sur == 1)
		pat.total = s.tonsillectomy; //This line is where it says total is innaccessible
}
The first friend declaration fails because PatientAccount has not been declared yet. It should work if you place a forward declaration of Surgery at the beginning of the code.
class Surgery;
Last edited on
Ok that worked thanks
Topic archived. No new replies allowed.