Is there a way to declare a pointer in the header file and instantiate it in .cpp?

Just like my question says: Is there a way to declare a pointer in a header file and instantiate it in .cpp?

I still have this:

.h:

FILE* stream;

.cpp

stream = fopen("com2", "r");

But this will give me this error:

1> gpsHandler.obj: error LNK2001: unresolved external symbol "struct _iobuf * stream" (? Stream @@ 3PAU_iobuf @@ A) 1> C: \ Users *** \ portReading \ Debug \ portReading.exe: fatal error LNK1120: 1 unresolved external

+3
source share
2 answers

As long as the variable in the source file is not static(internal link), you can declare this variable in the header file with extern FILE* stream;. This is how we declare global variables:

.h:

extern FILE* stream;

.cpp

FILE* stream;

, , #include <cstdio>

+5

extern FILE* straem; ?

+1

All Articles