C++出错.请高手指点 友元函数问题 20
这是我的源代码总是有一个错误,请高手指点#include<iostream>usingnamespacestd;classCar;classBoat{public:Boa...
这是我的源代码
总是有一个错误 ,请高手指点
#include<iostream>
using namespace std;
class Car;
class Boat
{
public:
Boat(float a=0){weight=a;}
SetWeight(float a){weight=a;}
friend float totalweight(Boat &x,Car &y);
private:
float weight;
};
class Car
{
public:
Car(float b=0){weight=b;}
SetWeight(float b){weight=b;}
friend float totalweight(Boat &x,Car &y);
private:
float weight;
};
float totalweight(Boat &x,Car &y)
{
return x.weight+y.weight;
}
void main()
{
Boat b(10);
Car c;
float sum;
c.SetWeight(15);
sum=totalweight(b,c);
cout<<"totalweight="<<sum<<endl;
} 展开
总是有一个错误 ,请高手指点
#include<iostream>
using namespace std;
class Car;
class Boat
{
public:
Boat(float a=0){weight=a;}
SetWeight(float a){weight=a;}
friend float totalweight(Boat &x,Car &y);
private:
float weight;
};
class Car
{
public:
Car(float b=0){weight=b;}
SetWeight(float b){weight=b;}
friend float totalweight(Boat &x,Car &y);
private:
float weight;
};
float totalweight(Boat &x,Car &y)
{
return x.weight+y.weight;
}
void main()
{
Boat b(10);
Car c;
float sum;
c.SetWeight(15);
sum=totalweight(b,c);
cout<<"totalweight="<<sum<<endl;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询