#include “Cow.h”
#include “pork.h”
#include “Goat.h”
Cow::Cow(int weight)
{
this->weight = weight;
}
pork Cow::operator+(const Goat& goat)
{
/*加法规则:
一斤牛肉:两斤猪肉
一斤羊肉:三斤猪肉
/
int tmp = this->weight2+goat.getweight()*3;
return pork(tmp);
}
pork Cow::operator+(const Cow& cow)
{
int tmp = (this->weight + cow.weight) * 2;
return pork(tmp);//返回一个猪肉类的对象
}
Cow Cow::operator+(int n)
{
int tmp = weight + n;
return Cow(tmp);
}
string Cow::describe()
{
stringstream str;
str << weight << “斤牛肉”;
return str.str();
}
来源:CSDN
作者:qq_44699909
链接:https://blog.csdn.net/qq_44699909/article/details/104219857