My question is for the last statement i.e. before return 0;
Why the parametrize constructor is being called when we are trying to assign an int value to an object.
My piece of code:
#include<iostream>
using namespace std;
class Test {
private:
int i;
public:
Test(int s=0):i(s) {
cout<<"param ctor: "<<i<<endl;
}
};
int main()
{
Test a; //param ctor called
Test b(5); //param ctor called
//b(a); //error as we have not implemented copy ctor
b=a; //compiler provided assignment opr. called
b=100; //why param ctor called for this.??
return 0;
}
OUTPUT:
param ctor: 0
param ctor: 5
param ctor: 100