c++ 这个函数的输出是什么?

c++ What's the output of this function?

这个程序的输出应该是这样的:

谁能解释为什么这个 main 的输出是:

F1/2F2/3F5/4F0/1F0/1F0/1F0/1F0/1

K0/1 K0/1

K?/? K2/3K1/2

你能解释一下我们是如何得到最后两行的吗? 谢谢

构造函数在fraction.h

中是这样初始化的
Fraction(int n=0, int d=1);

 /* fraction.cpp */
#include "fraction.h"
#include <iostream>
using namespace std;
Fraction::Fraction(int n, int d)
: numerateur(n)
{
dedominateur = d;
cout << "F" << n << '/' << d << ' ';
simplifier();
}
Fraction::~Fraction(){
    //cout<<"destructeur";
cout << "K"
<< numerateur << '/'
<< dedominateur << ' ';
numerateur = dedominateur = 0;
}
void Fraction::simplifier(){/*...*/}

  /* prog1.cpp */
#include <iostream>
#include "fraction.h"
using namespace std;
void test(Fraction a, Fraction& b){
Fraction* c = new Fraction(a);
a = b;
b = *c;
c = NULL;
cout<< "F";
return;
}
int main(){
Fraction f1(1,2), f2(2,3), f3(5,4);
Fraction* tab = new Fraction[5];
std::cout << std::endl;
test(f1, tab[2]);
test(tab[3], tab[4]);
f3 = tab[5];
std::cout << std::endl;
return 0;
}

带有K的输出显然来自析构函数。其中两个来自参数 a,它按值(复制)传递给 test。其他三个是main第一行的。

new 创建的对象永远不会 delete,因此它们永远不会被破坏。