上面的例题问?
xddjd 2001-11-29 07:08:51 当我用#include <iostream.h>编译,次程序可以通过!
假如用
#include <iostream>
using namespace std;
编译会出现以下错误:(错误指向第一个friend函数)
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
Error executing cl.exe.
rmbf.exe - 1 error(s), 0 warning(s)
请问大侠原因何在?为什么不可以用第二种方式?
#include <iostream.h>
class RMB
{
public:
RMB(unsigned int d, unsigned int c);
friend RMB operator +(RMB&, RMB&);
friend RMB& operator ++(RMB&);
void display()
{
cout <<(yuan + jf/100.0) << endl;
}
protected:
unsigned int yuan;
unsigned int jf;
};
RMB::RMB(unsigned int d, unsigned c)
{
yuan = d;
jf = c;
while(jf >= 100)
{
yuan ++;
jf -= 100;
}
}
RMB operator + (RMB &p, RMB &q)
{
unsigned int jf = p.jf + q.jf;
unsigned int yuan = p.yuan + q.yuan;
RMB result(yuan,jf);
return result;
}
RMB& operator ++(RMB &q)
{
q.jf++;
if(q.jf >= 100)
{
q.jf -= 100;
q.yuan++;
}
return q;
}
void main()
{
RMB d1(1,60);
RMB d2(2,50);
RMB d3(0,0);
d3 = d1 + d2;
++ d3;
d3.display();
}