为什么我的朋友操作重载代码的输出结果为零

时间:2017-03-06 19:40:01

标签: c++ c++11

当我尝试运行此代码时,我得到的输出为零,这是不期望的,根据我已经定义的我应该得到-1而不是0,我已经尝试更改x的值,我已经尝试查找垃圾值,如果有的话。你们的想法是什么?

imaplib

1 个答案:

答案 0 :(得分:0)

排序。

#include<iostream>
using namespace std;
class nf{
    int x;
    public:
    nf()
    {
        x=1;
    }
    nf(int a){
        x=a;
    }
friend nf operator ++(nf &n1)
{
    n1.x=-n1.x;
}
void display()
{
    cout<<x;
}



};
int main()
{
 nf c1;
 ++c1;
 c1.display();

}
相关问题