源代码
#include<iostream>
using namespace std;
class sample
{
friend void operator ++(sample s1);//定义重载函数为友元函数
friend int operator -(sample s2);//定义重载函数为友元函数
int n;
public:
sample(int i) {n=i;}
//int operator -() {n=-n; return n;}
//2void operator ++() {n++; }//前缀运算
//void operator ++(int) {n++; }//后缀运算
void operator ++(int) {n+=1; }
void display()
{
cout << "n="<<n<<endl;
}
};
int operator -(sample s2) {s2.n=-s2.n; s2.display();}//类外面定义一个运算符重载
void operator ++(sample s1) {s1.n++; s1.display();}//类外面定义一个运算符重载
main ()
{
sample b(6),a(6),c(6);
++b;
a++;
-c;
a.display();
b.display();
c.display();
}
问题
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.
解决:换个编译器,vc6.0的问题