NULL global variable

P

person

Hi,

I've got a global variable, type * var_name, declared in one .cpp file.
I assign it a value inside one of the methods in that file. I extern
it in other .cpp files. For some reason in all the other files it's
NULL (thus causing my program to crash when I try to use it). I know
it's getting assigned a legitimate value because I can use it
successfully in the method right after it's assigned. The declaration
is not static. Will someone please tell me what I'm doing incorrectly?
It was working, then I had to go through a major overhaul of my
including of .h files due to a bizarre inheritance problem. Now it
doesn't work and I don't know if it's a side effect of the include
exercise or if something else has gone haywire. Any help/ideas would
be greatly appreciated.

Thanks,
Frank
 
B

BigBrian

Will someone please tell me what I'm doing incorrectly?

That's difficult/impossible without seeing code. Without code
anything would be just speculation and not quarenteed to be right
anyway. Post a minimal amount of code which shows the problem, then we
can tell you what's wrong.
 
V

Victor Bazarov

person said:
I've got a global variable, type * var_name, declared in one .cpp file.
I assign it a value inside one of the methods in that file. I extern
it in other .cpp files. For some reason in all the other files it's
NULL (thus causing my program to crash when I try to use it). I know
it's getting assigned a legitimate value because I can use it
successfully in the method right after it's assigned. The declaration
is not static. Will someone please tell me what I'm doing incorrectly?

Simple. You're not following the recommendations of FAQ 5.8.
It was working, then I had to go through a major overhaul of my
including of .h files due to a bizarre inheritance problem. Now it
doesn't work and I don't know if it's a side effect of the include
exercise or if something else has gone haywire. Any help/ideas would
be greatly appreciated.

Recompile/Rebuild all.

V
 
M

Mike Wahler

person said:
Hi,

I've got a global variable, type * var_name, declared in one .cpp file.
I assign it a value inside one of the methods in that file. I extern
it in other .cpp files. For some reason in all the other files it's
NULL (thus causing my program to crash when I try to use it). I know
it's getting assigned a legitimate value because I can use it
successfully in the method right after it's assigned. The declaration
is not static. Will someone please tell me what I'm doing incorrectly?
It was working, then I had to go through a major overhaul of my
including of .h files due to a bizarre inheritance problem. Now it
doesn't work and I don't know if it's a side effect of the include
exercise or if something else has gone haywire. Any help/ideas would
be greatly appreciated.

You have a bug on line 42.

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top