即使該類已被聲明爲朋友類,數據成員也無法訪問。錯誤:「總」在此範圍儘管該類已聲明爲朋友類,但數據成員無法訪問
#include <iostream>
#include <iomanip>
using namespace std;
class Produce
{
private:
float total;
public:
Produce()
{
total=0;
}
friend class Bill;
};
class Bill
{
private:
float grand_total;
public:
Bill()
{
grand_total=0;
}
Bill operator+=(const Produce &p)
{
return Bill(total+p.total);
}
};