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.

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! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.