Is it safe to return object from within namespace. In below code call()
is returning bag object by value. But scope of newly created object is within namespace... so had a doubt if it is right way to do it.
namespace abc{
class bag{
public:
bag()
{
cout<<"\nconstructor called";
}
~bag()
{
cout<<"\ndestructor called";
}
bag(bag &c)
{
cout<<"\ncopy constructor called";
}
bag call()
{
bag f;
return f;
}
};
My second question is regarding copy constructor.
In main()
i am trying to call copy constructor by using following expression, but compiler is throwing error... how can i achieve this
abc::bag b;
abc::bag c=b.call(); // trying to call copy constructor ,but getting compile time error