Hello everyone,

I hope I can write this question clearly. Anyway, it is about global variables. I have several files in my C++ project. One of which is main.cpp. This file comtains my main() function. I have a few other files in my project. They are server.cpp, server.h, strings.h, includes.h and functions.h. My main.cpp function #includes the includes.h file which includes strings.h and functions.h.

My main() function fills a variable located win strings.h called sysName[32]. My main() function then calls a function in server.cpp. Becuase I delcared a prototype in server.h, it works. Now, my function in server.cpp cannot read my sysName variable even though #include "includes.h" is located in its header file.

Why can't I access this variable. I think all the #includes are correct?

I have been searching google and have been working on this for like 2 hours now with no luck.

Thanks for any help.

12 Years
Discussion Span
Last Post by calcop

since you didn't post any code we can only guess. sysName is apparently NOT declared in any of the header files that are included in server.cpp. user the extern keyword like below.

// includes.h
[b]extern [/b] char sysName[32];

Thank you! Took me forever to find out what I was missing. Thanks again! :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.