我想做类似以下的事情:
class Foo
{
Foo(int &&a, int b, std::string s="");
// does not compile because a is not an rvalue:
// Foo(int &&a, std::string s) : Foo(a, 0, s) {}
Foo(int &&a, std::string s) : Foo(std::move(a), 0, s) {} // move a
}
- 这是一般重载构造函数的有效方法吗?
- 特别是一个将右值引用作为参数的?
根据评论编辑
澄清一下,我是移动语义的新手(也是一名业余程序员),我只是不确定这是否是处理这种情况的好方法。
我根据评论(现已删除)添加了第一个问题,该评论表明这不是重载构造函数的正确方法。