Sharing Shared Objects - Defined but Not Used Warning

I have several C ++ classes, many of them (not all) use two "static size variables", for example.

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 put them in the header file along with other objects that share all classes.

When I compile the project, I get a lot of warnings (from classes that don't use them) that complain that they are defined and not used. But I need them!

So, I ask, is there a way to define them so that classes, without using these two variables, can use this header file without throwing a warning that they are not defined?

Thank you in advance

+5
3

const, extern . , ( ), , .

, , , . ( , , , ).

+11

, . , , . , - , .

, static . , .c .cpp, , .

, a.cpp b.cpp, share.h, a.cpp width 20, b.cpp . . , static size width , , , . , , .

, static . , :

const size width=10;//Used by about 60% 
const size height = 12;//Used by about 60% 

, , extern ( ), .cpp ( extern, ). :

//share.h
extern size width;
extern size height;

//share.cpp
size width = 10;
size height = 12;
+8

You need to use the const constructor, not the static one. The value of statics is completely different from your intentions. You can find more information about statics here http://www.cprogramming.com/tutorial/statickeyword.html .

+1
source

All Articles