I wrote sample (below) program to check when copy constructor and assignment operator called.
my doubt was if object a, b defined previous to statement a(b), then will a(b) call copy c_tor or assignment operator and why below program giving compilation error(mentioned inline) . Can anybody tell me how to fix the issue.
I have tried using test(test& y) , still compiler gives "
no matching function for call to ‘test::test(test)’"
Code:
#include<iostream>
using namespace std;
class test
{
int i;
public:
test(int x=0):i(x){}
~test(){}
test(const test& y)
{
cout<<"cp_ctor"<<endl;
}
test& operator=(test& m)
{
cout<<"assingment"<<endl;
return *this;
}
};
test sentobject(void)
{
test temp(88);
cout<<"sending..";
return temp;
}
int main()
{
test a(3),b(6);
cout<<"a(b)calls";
a(b);//error: no match for call to ‘(test) (test&)’
cout<<"sendobject calls"<<endl;
test k = sentobject();
return 0;
}

