小编had*_*ali的帖子

C++ 无法找到命名空间之外的函数

编译以下代码失败,因为第二个函数无法找到第一个函数,即使它位于命名空间之外。我自己无法弄清楚这个问题,到目前为止我也没有在网上找到任何答案。

测试.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 …

c++ overloading operator-overloading name-lookup

6
推荐指数
1
解决办法
1287
查看次数

什么:= VB中的意思?

我一直在使用Visual Studio,我使用VB.现在我注意到text:=在编码时它给我的IntelliSense建议列表中调用了一些东西.我不确定它是什么.有谁可以向我解释一下?

vb.net colon-equals

2
推荐指数
1
解决办法
650
查看次数