我有一个程序不知道怎么了, 在VC上运行了,有一个错误。我不知道怎么改,可是我自己看是没有问题的,请大家帮我改一下啊,最好告诉我什么原因,运行的结果是怎么得来的。谢谢啊! static int m=1; #include <stdio.h> class CType { int n; friend CType& operator ++ (const CType& q); friend void main(); friend CType operator -(const CType & r); public: CType(int r) {n=r;} int operator !();
}; int CType::operator !() { printf("%d!,",m++);} CType operator -(const CType & r)
{ printf("%d-,",m++); return CType (-r.n); } CType operator ++(CType & q) { printf("%d++,",m++); ++q.n ; return q ; } void main() { CType a(2),b(-1); a=!-++b; printf("a=%d\n",a.n); a=(operator -(operator++(b))).operator!(); printf("a=%d",a.n); }
错误是: files\microsoft visual studio\myprojects\021\021.cpp(27) : error C2248: 'n' : cannot access private member declared in class 'CType' e:\program files\microsoft visual studio\myprojects\021\021.cpp(5) : see declaration of 'n' 劳驾啊!