I need to define my queue globally in a header file. And I of course include that header in other classes.
but I constantly receive multiple definition of variable xx.
how can I declare it only once? so for the next times compiler ignores it?
Printable View
I need to define my queue globally in a header file. And I of course include that header in other classes.
but I constantly receive multiple definition of variable xx.
how can I declare it only once? so for the next times compiler ignores it?
You need to define the variable in a cpp file (not in header file).
The header file will have just declaration of the variable with "extern" keyword as prefix, and without intilaization.
For extern variable:
ex: extern QList mylist;
ForUse header guards,Quote:
but I constantly receive multiple definition of variable xx.
Ex:
#ifndef GLOBAL_H
........
#endif
hope it helps,
Bala
Using guard macro in header file is a good practice, but it will not solve the multiple definition problem/errorQuote:
Originally Posted by BalaQT
No, you don't have to set it global. But even if you did, you wouldn't do it in a header file as these get included into multiple compilation units causing mutliple declaration problems as the one you're suffering from right now. I think this is a good moment to suggest spending some time with a good book on object-oriented programming before tackling real problems.