为什么我的朋友操作超载代码将输出算出为零
Why is the output is coming out to be zero for my friend operation overloaded code
当我试图运行此代码时,我将输出视为零,这不是我所定义的,我应该得到-1而不是0,我尝试更改X的值,如果有的话,我尝试查找垃圾值。你们想什么?
#include<iostream>
using namespace std;
class nf {
int x;
public:
nf() {
x=1;
}
nf(int a) {
a=x;
}
friend nf operator ++(nf n1) {
n1.x=-n1.x;
}
void display() {
cout<<x;
}
};
int main()
{
nf obj(1),obj2;
obj2=++obj;
obj2.display();
}
排序。
#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();
}
相关文章:
- 为什么我的代码在输出中增加了93天
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 为什么我的C++程序的程序集输出充满了 .ascii,没有汇编代码?
- 为什么我的 if else 语句不起作用并从数组中输出正确的索引?
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 我的输出中有一个额外的 0,为什么会这样
- 为什么我的 cout 在输出中没有显示字符串?
- 为什么即使使用 for 循环遍历我的向量,它也没有输出到控制台?(C++)
- 为什么我的输出与输入不同?(C++)
- 当使用我在一个函数、另一个函数中修改的数组时,在我的输出中得到一个奇怪的负数
- 为什么我的代码块上没有显示输出?
- "Program ended with exit code: 0"出现在我的输出的开头?
- 为什么这一行不输出我的文本文件?
- 有没有办法用单行逻辑代码打印金字塔星形图案?面试官向我的朋友问了这个问题
- 我的朋友功能无法访问私人变量
- 如果类外是我的朋友,类外::内也是
- 为什么我的朋友操作超载代码将输出算出为零
- 在任何情况下都会出现意外输出.我的解决方案出了什么问题
- 我的朋友无法在他的 linux 发行版上运行我的 openGL 程序
- 我如何发送一个unix-exe给我的朋友,这样他就可以通过双击运行它