5
下面的代码编译失败ADL使用std类型无法找到经营者
namespace A {
using C = std::vector<std::string>;
std::ostream& operator << (std::ostream& lhs, const C& rhs) {
lhs << 5;
return lhs;
}
}
int main()
{
A::C f;
std::cout << f;
return 0;
}
与错误
Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'A::C' (or there is no acceptable conversion)
显然它不能找到< <运营商大概是由于考虑到c是一个类来自std命名空间。有什么方法可以确保编译器找到这个操作符或者解决这个问题吗?
以运营商出的命名空间应该工作的。 – interjay
'A :: operator <<(std :: cout,f);'但是我怀疑你在找什么。 – DeiDei
'A :: C'不是一个类型定义,它只是一个别名。该类型存在于'std'命名空间中。 –