C++的运算符重载问题
G:\C++工程\菜品\main.cpp(14) : fatal error C1001: INTERNAL COMPILER ERROR(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.
菜品.exe - 1 error(s), 0 warning(s)
代码是这个,想知道 为什么,觉得应该没错的啊。
#include<iostream>
using namespace std;
class food
{
public:
food(){};
~food(){};
void print();
private:
int money;//价钱
int number;//数量
friend food operator +(food &d1,food &d2);
};
food operator+ (food &d1,food &d2) //普通函数的+好重载
{
food f1;
f1.money=d1.money+d2.money;
f1.number=d1.number+d2.number;
return f1;
}
void food::print()
{
cout<<money<<endl;
cout<<number<<endl;
}
int main()
{
food f1(28,4),f2(36,9),f3;
f3=f1+f2;
cout<<f3.print<<endl;
return 0;
}