[英]problems with overload resolution and operator<< for templated types
[英]Templated operator=() and overload resolution
考虑以下代码片段:
#include <utility>
struct test {
template <class Other>
test& operator=(Other&&);
int& i_;
};
int main() {
int i = 0;
test t1{i}, t2{i};
t1 = std::move(t2); // tries to select the implicitly-declared one!
}
当尝试使用 GCC11.1 (使用-std=c++2a
)进行编译时,它会尝试 select 编译器生成的operator=
,该操作符被删除并失败。 之前的 GCC 版本成功构建了此代码。
据我了解,隐式生成的已删除operator=
是不可行的,因此应选择 operator 模板。 是 GCC 错误还是我遗漏了什么?
这似乎是一个错误。 它在 GCC 11.2 上查找模板化方法,但正如您所提到的,它在 GCC 11.1 上看到已删除的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.