搞了好久还是不行QAQ代码如下 无法访问的是car类的weight1
#include<iostream>
using namespace std;
class car;
class boat {
public:
boat(float w = 0)
{
weight = w;
}
float boat::gettotalweight(car &A);
private:
float weight;
};
class car{
public:
car(float w = 0)
{
weight1 = w;
}
friend float gettotalweight(car &A);
private:
float weight1;
};
float boat::gettotalweight(car &A)
{
return weight + A.weight1; //就是这里的A.weight1无法访问!!!
}
int main()
{
boat A(5);
car B(3);
float C;
C=A.gettotalweight(B);
}
#include<iostream>
using namespace std;
class car;
class boat {
public:
boat(float w = 0)
{
weight = w;
}
float boat::gettotalweight(car &A);
private:
float weight;
};
class car{
public:
car(float w = 0)
{
weight1 = w;
}
friend float gettotalweight(car &A);
private:
float weight1;
};
float boat::gettotalweight(car &A)
{
return weight + A.weight1; //就是这里的A.weight1无法访问!!!
}
int main()
{
boat A(5);
car B(3);
float C;
C=A.gettotalweight(B);
}