Global Variables

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2005
Posts: 27
Reputation: calcop is an unknown quantity at this point 
Solved Threads: 0
calcop calcop is offline Offline
Light Poster

Global Variables

 
0
  #1
Jan 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,653
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Global Variables

 
0
  #2
Jan 16th, 2006
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];
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 27
Reputation: calcop is an unknown quantity at this point 
Solved Threads: 0
calcop calcop is offline Offline
Light Poster

Re: Global Variables

 
0
  #3
Jan 16th, 2006
Thank you! Took me forever to find out what I was missing. Thanks again!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 3502 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC