友元函数无法访问私有成员

友元函数无法访问私有成员,一个可以一个不行

img

#include <iostream>
using namespace std;
class Cat
{
public:
    Cat(double w) :weight(w) 
    {
        numOfCats++;
        cout << "Cat Object is constructing, the constructed Number is " << numOfCats << ", and the lived Number is" << numOfCats - numOfCatsGo << endl;
    }
    static int getNumOfCats(bool IsConstruted);
    friend double getTotalWeight(Cat&,Boat&);
    ~Cat()
    {
        numOfCatsGo++;
        cout << "Cat Object is deconstructing, and the lived Number is " << numOfCats - numOfCatsGo << endl;
    }
private:
    static int numOfCats, numOfCatsGo;
    double weight;
};
int Cat::numOfCats = 0;
int Cat::numOfCatsGo = 0;
class Boat
{
public:
    Boat(double w) :weight(w){}
    friend double getTotalWeight(Cat&,Boat&);
private:
    double weight;
};
int Cat::getNumOfCats(bool IsConstruted)
{
    if (IsConstruted)
        return numOfCats;
    else
        return numOfCatsGo;
}
double getTotalWeight(Cat&c,Boat&b)
{
    return (c.weight + b.weight);
}

int main()
{
    int n;
    double w0, w1;
    cin >> n >> w0 >> w1;
    for (int i = 0; i < n; i++)
    {
        Cat* c = new Cat(w0);
        delete c;
    }
    cout << "Cat Object is constructing, the constructed Number is " << Cat::getNumOfCats(true) << ", and the lived Number is " << Cat::getNumOfCats(true) - Cat::getNumOfCats(false) << endl;
    Cat c(w0);
    Boat b(w1);
    cout << getTotalWeight(c, b) << endl;
    cout << "Cat object is deconstructing, and the lived Number is " << Cat::getNumOfCats(true) - Cat::getNumOfCats(false) << endl;
    std::cout << "Hello World!\n";
}

这样看不出问题,看看完整代码