Jump to content
  • Advertisement
Sign in to follow this  

Defining variables in C++ header files

This topic is 3708 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!