I am trying to use a static const field which I define inside a class.
When I define it like that:
class DisjunctionQuery : public Query
{
public:
DisjunctionQuery ();
static const std::string prefix;
};
const std::string DisjunctionQuery::prefix = "Or";
It says: multiple definition of ‘DisjunctionQuery::prefix’
and if I change it that way (remove the two lines):
class DisjunctionQuery : public Query
{
public:
DisjunctionQuery ();
//static const std::string prefix;
};
//const std::string DisjunctionQuery::prefix = "Or";
It says when I try to call it in another place ‘prefix’ is not a member of ‘DisjunctionQuery’.
How can I make it work?
thanks.
You move the definition to a single implementation file.
If you keep it in the header, you’ll break the one definition rule. Each file that includes the header will attempt to define the
staticmember, which is wrong.