dimanche 1 octobre 2017

Why constructors not called? [duplicate]

This question already has an answer here:

In the following code, I have two parametrizes constructors. I have compiled and run into Gcc compiler but constructors not called.

#include <iostream>

class A 
{
  A(int i) 
  { 
      std::cout << "A constructed" << std::endl; 
  }
};

class B 
{
  B(A a1) 
  { 
      std::cout << "B constructed" << std::endl; 
  }
};

int main() 
{
  int i = 5;
  B b1(A(i));
  std::cout << i << std::endl;
  return 0;
}

Output:

5

So, Why constructors not called?

Aucun commentaire:

Enregistrer un commentaire