R
Rune Allnor
Hi all.
I have a template class where I have defined some
constants in a header file, along the lines of
////////////////////////////////////////////
class flags{
static const size_t flag;
};
const size_t flags::flag = 1;
////////////////////////////////////////////
This compiles and runs nicely in the Boost.Test program,
but when I try to use the template class in a Qt GUI program,
the linker starts complaining about the constants as being
multiple defined objects:
- in main.obj
- in moc_myfile.obj
- in myfile.obj
I have included the standard guard about multiple inclucions
of the header files, and I can see why these constants would
appear in myfile.obj, as I include the file where they are declared
from myfile.h. However, I have no idea why the constants should
be available in main.obj or moc-myfile.obj - that's where Qt come
in to do its thing.
There isn't much I can do about the ways Qt twists and turns
the code into an executable, so I suppose my only hope
is to be able to resolve the 'multiple definition' problem.
Any hints on how to do this?
The flags class will exist in millions of instances, so I can not
afford to include the flag definintions as const variables in the
class.
Rune
I have a template class where I have defined some
constants in a header file, along the lines of
////////////////////////////////////////////
class flags{
static const size_t flag;
};
const size_t flags::flag = 1;
////////////////////////////////////////////
This compiles and runs nicely in the Boost.Test program,
but when I try to use the template class in a Qt GUI program,
the linker starts complaining about the constants as being
multiple defined objects:
- in main.obj
- in moc_myfile.obj
- in myfile.obj
I have included the standard guard about multiple inclucions
of the header files, and I can see why these constants would
appear in myfile.obj, as I include the file where they are declared
from myfile.h. However, I have no idea why the constants should
be available in main.obj or moc-myfile.obj - that's where Qt come
in to do its thing.
There isn't much I can do about the ways Qt twists and turns
the code into an executable, so I suppose my only hope
is to be able to resolve the 'multiple definition' problem.
Any hints on how to do this?
The flags class will exist in millions of instances, so I can not
afford to include the flag definintions as const variables in the
class.
Rune