我的这个程序是关于重载的---运算符,也有友元函数。可是友元函数出了问题。 能告诉我关于++a--++和输出的X值的由来吗? #include<stdio.h> class CA { long x; public: CA(long m) {x=m;} void show() { printf("%d x=%d\n",number,x);} CA& operator++(); CA operator++(int); friend CA operator --(CA &,int); static int number; }; CA & CA::operator ++ () { ++x; printf("%d.CA::operator++();x=%d\n",number++,x); return *this; CA CA::operator ++ (int) { printf("%d.CA::operator++(int);x=%d\n",number++,x); CA temp(*this); x++; return temp; } CA operator--(CA& r,int)
{ printf("%d.CA::operator--(CA &r ,int);%d\n",number++,x); CA temp(*this); x--; return temp; } int CA::number=1; void main() { CA a(1); a.operator ++ (1); a.operator ++ (); ++a--++; a.show (); } 错误是::\Program Files\Microsoft Visual Studio\MyProjects\12\12.cpp(20) : error C2601: '++' : local function definitions are illegal E:\Program Files\Microsoft Visual Studio\MyProjects\12\12.cpp(27) : error C2601: '--' : local function definitions are illegal E:\Program Files\Microsoft Visual Studio\MyProjects\12\12.cpp(27) : fatal error C1903: unable to recover from previous error(s); stopping compilation Error executing cl.exe.