Reputation: 1354
What is the proper way of declaring variables in the header file in c++? And if it is not a good idea, then why? Thank you.
Upvotes: 0
Views: 1807
Reputation: 6091
The correct way would be to declare the variable with the extern keyword in the header file and then you have to declare it in one (!) cpp file without the extern keyword.
But:
Variables in header files are global variables. These have much problems. Here a few:
You should never use global variables in C++. They are only there for backward compatibility with C.
Upvotes: 4