You seem to be confusing your PrecicateData
namespace with a class. For the latter, you would declare a static
member in the header and then (most likely) actually define it elsewhere (for example, in "MyFile.cpp"). However, for a namespace
, data and functions are declared/defined in much the same way as for 'free' global variables.
So, either add the definition of your predicatemap
in the header, like this (you will, of course, need to place it after the definition of _InitPredicates
):
namespace PredicateData {
using PredicateCallable = std::function<bool(char)>;
enum class PredicateType {
LOWER_CASE_ALPHABET = 2147483648,
UPPER_CASE_ALPHABET = 1073741824,
NUMBER = 536870912,
SPACE = 268435456,
SENTENCE_PUNCTUATION = 134217728,
SPECIAL_CHARACTER = 67108864
};
using PredicateMap = std::unordered_map<PredicateType, PredicateCallable>;
static PredicateMap _InitPredicates()
{
PredicateMap tmp;
//do something to tmp
return tmp;
}
static PredicateMap predicatemap = _InitPredicates();
}
Or, alternatively, declare predicatemap
as extern
:
namespace PredicateData {
using PredicateCallable = std::function<bool(char)>;
enum class PredicateType {
LOWER_CASE_ALPHABET = 2147483648,
UPPER_CASE_ALPHABET = 1073741824,
NUMBER = 536870912,
SPACE = 268435456,
SENTENCE_PUNCTUATION = 134217728,
SPECIAL_CHARACTER = 67108864
};
using PredicateMap = std::unordered_map<PredicateType, PredicateCallable>;
extern PredicateMap predicatemap;
static PredicateMap _InitPredicates()
{
PredicateMap tmp;
//do something to tmp
return tmp;
}
}
and then provide the definition in your source file (but note, you will also need to add the PredicateData::
namespace to the _InitPredicates()
function):
PredicateData::PredicateMap PredicateData::predicatemap = PredicateData::_InitPredicates();
Also note that the use of static
before enum class
is not permitted (I have removed it in the code samples above).