I'm a beginner in C++ and I have a hard time understanding this program from an exercise book, specifically why is the empty constructor called 6 times in total:
#include <iostream>
class Allo{
 public:
   Allo(int x_=0)
    : x(x_)
   {
     std::cout << "A" << x << " ";
   }
   Allo(const Allo& autre)
    : x(autre.x)
   {
     std::cout << "B" << x << " ";
   }
   ~Allo() {
     std::cout << "C" << x << " ";
   }
   int x;
};
void f1(Allo a1, Allo* a2, Allo* a3){
   a1.x++;
   a2->x -= 1;
   a3+=1;
   (a3->x)+=2000;
}
int main(){
   Allo tab[3];
   Allo a(20);
   Allo* b = new Allo(5);
   Allo* c = tab + 1;
   f1(a, b, c);
   std::cout << std::endl << "-------" << std::endl;
   Allo* t = new Allo[4];
   t[2] = Allo(9);
   std::cout << std::endl;
   return 0;
}
And the output is :
A0 A0 A0 A20 A5 B20 C21 
-------
A0 A0 A0 A0 A9 C9 
C20 C2000 C0 C0
Showing that the empty constructor is called 4 times at the end. Why is that? Shouldn't t[2] = Allo(9); be the last line calling the constructor?
 
    