On 2 Dec 2012, at 22:05, Jason Liu wrote:

>>> Basically I'm having an issue with a global variable.
>>> I have int songCounter declared outside of main in source file only
>>> [...]
>>> My guess is that instead of incrementing or decrementing songCounter
>>> directly, they're somehow creating local versions of the variable
>>> to work with instead. Any ideas on how to work around this?
>> 
>> Sounds like you forgot the "extern" keyword in the other files
>> so you are indeed creating a series of local songCounters in each
>> file instead of referring to the global one.
>> 
>> D.
>> 
> I've tried declaring songCounter in every way possible-- in source file only, 
> in header file only, static in source file, and in source and "extern" in 
> header, but none of those seem to affect how the program runs.


Hmm, sounds like you maybe need to step back and take a little time with a 
C/C++ book to review how global decls and extern are supposed to work, make 
sure you have it straight in your code.


For now, just to make it as simple as possible and to remove any extraneous 
decls that might be throwing things awry, what I'd suggest is removing any 
reference to your global songCounter from the header files and then, in the 
source files only:

- In exactly 1 (one) source file, somewhere near the top, in global scope (i.e. 
not inside any function or class or struct...) make the formal declaration for 
songCounter, like...

   int songCounter = 0;


Then, in every other file that needs to access that global, near the top, in 
global scope, put...

   extern int songCounter;


And you *should* be good to go - then every file will be explicitly referencing 
the one formally declared songCounter.

If that still does not work, then show us some code.

HTH,
-- 
Ian




_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to