我的遗留C ++代码下列位不编译:

#include <stdio.h>
#include <iostream>

extern ostream *debug;

GCC(克++)抱怨:

“之前‘*’标记的预期初始值设定”

环视它似乎更常见的声明这些作为外部参考,这样的:

extern ostream& debug;

为什么是一个指针不是有效的,但基准是在这种情况呢?

解决方案:

真正的问题,如下面所提到的是,在std ::命名空间符缺失。显然,这是常见于老年C ++代码。

有帮助吗?

解决方案

是,则可以使用的extern声明指针。你的错误很可能是你忘了使用std::资格:

// note the header is cstdio in C++. stdio.h is deprecated
#include <cstdio>
#include <iostream>

extern std::ostream *debug;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top