For the fun and experience of it, I'm modifying and exploring the source code for Blobby Volley 2 1.0 (Linux).
嗯...我would正在修改源代码,但我什至无法编译程序。 (悲伤,不是吗?)
这是导致错误的代码:
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
return stream << val.name << " (" << val.hostname << ":" << val.port << ")";
}
尝试编译这个克++ 5.4.0给出以下(简化的输出 - 原始输出约为 443 行)错误消息:
错误:与“operator
返回流
我将代码简化为:
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
stream << "hello"; //can't get simpler than this, right?
return stream;
}
and got
错误:与“operator
流
调用它的代码如下所示:
std::cout << "duplicate server entry\n";
std::cout << info << "\n"; //it's called here
最令我惊讶的是我们都知道std::cout
及其同类可以处理char
arrays.
例如,
#include <iostream>
#include <string>
int main () {
const char a[6] = "hello";
std::cout << a << std::endl; //No problem here!
return 0;
}
工作顺利。
哦,还有一件事。
如果我包括<string>
,这有效:
std::ostream& operator<<(std::ostream& stream, const ServerInfo& val) {
stream << std::string("hello");
return stream;
}
有谁知道我错过了什么?
PS:这是一个错误的粘贴。
PPS:这是请求的标头:
/* header include */
#include "NetworkMessage.h"
/* includes */
#include <cstring>
#include "UserConfig.h"
#include "SpeedController.h"
PPS:如果您想知道为什么我没有收到有关的错误std::ostream
没有被定义,请检查 Sam 答案的第三段。