mercredi 28 mars 2018

Error: 'global' does not name a type while accessing global variables across different files.

I have a total of 3 files, file1.h/.cpp and file2.cpp. I want to use global variables of file1.h in file2.cpp. On compiling file2.cpp I am getting error as:

*error*: 'global' does not name a type

'global' is the name of the variable.

file1.h

extern int global;

file1.cpp

int global = 0;

file2.cpp

#include file1.h;   

global =5;

Aucun commentaire:

Enregistrer un commentaire