Can you declare a pointer as extern in C ++?
I have the following bit of legacy C ++ code that won't compile:
#include <stdio.h>
#include <iostream>
extern ostream *debug;
GCC (g ++) complains: "expected initializer before" * token "
Looking around, it seems more common to declare them as external links, for example:
extern ostream& debug;
Why is the pointer invalid but the link is in this situation?
DECISION:
The real problem, as mentioned below, is the lack of the std :: namespace specifier. Apparently this was common in older C ++ code.
+1
postfuturist
source
to share
1 answer
Yes, you can declare a pointer using extern. Your mistake, most likely you forgot to qualify with std::
:
// note the header is cstdio in C++. stdio.h is deprecated
#include <cstdio>
#include <iostream>
extern std::ostream *debug;
+7
Johannes Schaub - litb
source
to share