编译以下代码失败,因为第二个函数无法找到第一个函数,即使它位于命名空间之外。我自己无法弄清楚这个问题,到目前为止我也没有在网上找到任何答案。
测试.cpp:
#include <bits/stdc++.h>
struct myclass {};
template <typename T, typename U>
std::ostream& operator<< (std::ostream &os, const std::pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
namespace my {
void operator<< (std::ostream os, myclass m) {
std::cout << std::pair<int, int>(5, 4); // This is line 13.
}
}
int main() {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器给出的错误( g++ test.cpp -O2 -o test.exe):
test.cpp:13:13: error: no match for 'operator<<' (operand types are …
我一直在使用Visual Studio,我使用VB.现在我注意到text:=在编码时它给我的IntelliSense建议列表中调用了一些东西.我不确定它是什么.有谁可以向我解释一下?