我正在读这篇文章。
我达到了以下代码。
我想知道:
对字符串有用吗
std::move
(假设字符串足够长)?它会使先前的字符串无效吗?
我应该在哪里使用它,在哪里不应该使用它?
.
class Name
{
public:
Name(std::string firstName, std::string lastName)
: firstName_(std::move(firstName))
, lastName_(std::move(lastName)) {}
void print() const
{
std::cout << lastName_ << ", " << firstName_ << '\n';
}
private:
std::string firstName_;
std::string lastName_;
};
我的技术一直在使用
constructor(const std::string& argument): field(argument)