【发布时间】:2012-11-22 15:37:54
【问题描述】:
忽略我所描述的理智,使用std::move() 函数在将参数传递给基本构造函数时会缩短构造时间吗?
struct Bar {
Bar(std::string);
std::string _s;
}
struct Foo : public Bar {
Foo(std::string);
}
struct Bar(std::string bs) : _s(std::move(bs)) {
// 1
}
struct Foo(std::string fs) : Bar(std::move(fs)) {
// 2
}
那么在这个例子中,Foo 的构造函数中使用的move() 是否会阻止对字符串进行额外的复制?
为了澄清,这种设计是否意味着不应尝试在 // 1 和 // 2 点上使用 bs 和 fs,但在这两个地方使用 _s 是安全的?
【问题讨论】:
标签: c++ constructor c++11 move-semantics