944,028 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 5350
  • C++ RSS
Jan 16th, 2006
0

Global Variables

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005
Jan 16th, 2006
0

Re: Global Variables

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
extern  char sysName[32];
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,953 posts
since Aug 2005
Jan 16th, 2006
0

Re: Global Variables

Thank you! Took me forever to find out what I was missing. Thanks again!
Reputation Points: 10
Solved Threads: 0
Light Poster
calcop is offline Offline
27 posts
since Oct 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Trouble getting code to compile
Next Thread in C++ Forum Timeline: How do I delete an instance of an Array?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC