從命名空間返回對象是否安全?在下面的代碼call()
按值返回包對象。但是新創建的對象的範圍在命名空間內......所以有一個疑問,如果它是正確的方式來做到這一點。從命名空間返回對象是否安全?
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;
}
};
我的第二個問題是關於複製構造函數。 在main()
我試圖通過使用下面的表達式調用拷貝構造函數,但是編譯器拋出錯誤......我如何才能做到這一點
abc::bag b;
abc::bag c=b.call(); // trying to call copy constructor ,but getting compile time error
什麼是編譯時錯誤? –
你不必懷疑,您有任何疑問,請參閱http://www.cs.uic.edu/bin/view/Jakob/IndianEnglish –