I have a number of C++ classes, alot of them (not all) share two "static size variables" e.g.
share.h
/*Other variables in this header used by all classes*/
static size width=10;//Used by about 60%
static size height = 12;//used by about 60%
So I placed them in a header file along with other objects that all classes share.
when I compile the project I get alot of warnings (from the classes which dont use these), which complain about them being defined and not used. But I need them there!
So I ask, is there a way to define these, so that classes not using these two variables can use this header file without throwing warnings about them not being defined?
Thank you in advance
Either declare them const
, or declare them extern
and define them in exactly one source file. A compiler should expect constants to be defined (in header files) but not used, and not give a warning for that.
Defining static variables that you don't use is often a sign of an error, so the warning is useful in that case. (If you actually do want separate, modifiable copies of these variables in multiple translation units, then you should probably rethink your program design).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With