C problem how many times does the default constructor and co
C++ problem:
how many times does the default constructor and copy constructor being invoked?
int pob2(dice d1, dice d2, dice &d3){
dice a(d1);
dice b(d2);
dice c=d3;
int result =(a+b);
result = result +c.getvalue();
return result;
}
int main()
{
dice one, two(6), three;
cout<<p2(one, two, three)<<endl;
return 0;
}
Solution
Answer:
default constructor is being invoked 2 times. while creating these dice objects \"one\", \"three\", default constructor will invoke.
copy constructor is being invoked 5 times.
while passing dice objects \"one\" and \"three\" to function p2(), copy constructor will invoke 2 times and inside p2() function while creating \"a\", \"b\", \"c\" dice objects, another 3 times copy contructor will invoke. so totally it will invke 5 times.
