我正在寻找这样的语法:
class Hugo
{
Hugo();
explicit Hugo( const Hugo& hugo );
Hugo GetRandomHugo()
{
Hugo hugo;
hugo.value = rand();
// this would fail:
// return hugo;
return Hugo(hugo); // explicit copy!!
}
};Run Code Online (Sandbox Code Playgroud)
换句话说:我正在寻找一种显式的复制语法,以允许方法返回一个副本,即使我的复制构造函数是显式的.
我正在使用GCC 4.4.5.
非常感谢,
查理