Sign in to follow this  

Defining variables in C++ header files

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this