I am facing a problem with this code
I don't know why the output is
A's constructor called
B's constructor called
A's constructor called
I thought it will print
"A's constructor called" another time for t object but assignment stopped that
why did assignment stop it ?
#include <iostream>
usingnamespace std;
class A
{
public:
int x = 3;
A() { cout << "A's constructor called" << endl; }
};
class B
{
public:
A a;
public:
B() { cout << "B's constructor called" << endl; }
A getA() { return a; }
};
int main()
{
B b1;
A tt;
A t = b1.getA();
return 0;
}