我已经看到过这样的其他问题,但我没有得到解决方案。 这是代码:
cout_overload.h:
#ifndef COUT_OVERLOAD_H_
#define COUT_OVERLOAD_H_
#include <iostream>
class A
{
private:
int data;
public:
A(int d);
friend std::ostream & operator <<
(std::ostream os, const A &t );
};
#endif
cout_overload_r.cpp:
#include <iostream>
#include "cout_overload.h"
A::A(int d)
{
data = d;
}
std::ostream &operator << (std::ostream &os, const A&t)
{
os << " t = " << t.data ;
return os;
}
main.cpp:
#include <iostream> #include "cout_overload.h"
int main(void)
{
A ra(1);
using std::cout;
// cout<<ra;
return 0;
}
答案 0 :(得分:3)
您需要修改request(target, function (err, resp, body) {
$ = cheerio.load(body);
links = $('a');
$(links).each(function (i, link) {
if ($(link).text().match('worker')) {
a = $(link).attr('href').toString(); // (*)
}
});
});
功能并在
friend
ostream&
并替换上面的行,
friend std::ostream & operator << (std::ostream os, const A &t );
因为friend std::ostream & operator << (std::ostream &os, const A &t );
是输出流,ostream
将通过引用传递(将流传递给函数的唯一方法)..