• Advertisement
Sign in to follow this  

Defining variables in C++ header files

This topic is 3492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I always thought that defining a variable in a header file would always lead to a multiple definition error. However it seems that something like:
// header.h
const int SOME_CONSTANT = 1024; // NO "static" here.
with header.h included in multiple .cpp files works fine and causes no error. 1/ Is it because the compiler just strips out the symbol and replaces it with it's constant value? (Even in debug builds?!) 2/ Is this guaranteed to cause no error or is it just compiler specific (and do you think it's good practice? (The compiler is Codewarrior)

Share this post


Link to post
Share on other sites
Advertisement
internal = static ?

I didn't know that, thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement