对不起,我不能带来更好的头衔.
最后一个&符号&在以下代码段中的含义如下:
A & A::operator=(A rhs) &
{
swap(*this, rhs);
return *this;
}
Run Code Online (Sandbox Code Playgroud)
根据答案我想知道:
operator=或可以应用于任何功能如果你需要更多的上下文,我在这里找到了这个语法:https://stackoverflow.com/a/12653520/951426
有一个小的解释,但我不明白.
编辑(格式化和简短回答我的问题):
operator=我试图了解在调用errno在 Linux上设置的 C 函数时应该使用哪个类别。
我不确定所有可能的错误代码都是由 POSIX 定义的,所以我很想使用system_category.
但是我喜欢稍后在我的代码中处理通用条件,所以我想做这样的事情:
std::error_code ec;
some_func(some_path, ec);
if (ec) {
if (ec == std::errc::file_exists) {
// special handling
}
return ec;
}
Run Code Online (Sandbox Code Playgroud)
要在 中设置错误代码some_func(),我希望像这样进行:
ec.assign(EEXIST, std::system_category());
Run Code Online (Sandbox Code Playgroud)
主要基于此讨论:
Run Code Online (Sandbox Code Playgroud)std::error_code ec; if(-1 == open(...)) ec = std::error_code(errno, std::system_category()); // To test using portable code if(ec == std::errc::no_such_file_or_directory) ... // To convert into nearest portable error condition (lossy, may fail) std::error_condition ec2(ec.default_error_condition())
但是,在 Linux 上,使用 GCC …