I have three files:
TableGenerataor.h
TableGenerataor.cpp
Analyzer.cpp
I have declared unordered_map in TableGenerator.h and using that I create the object of unorderd_map in TableGenerataor.cpp.
map_t obj1;
data d;
TableGenerator.h
namespace N {
typedef std::tuple<int, char> key_t;
struct key_hash : public std::unary_function<key_t, std::size_t>
{
std::size_t operator()(const key_t& k) const
{
return std::get<0>(k) ^ std::get<1>(k) ;
}
};
struct key_equal : public std::binary_function<key_t, key_t, bool>
{
bool operator()(const key_t& v0, const key_t& v1) const
{
return (
std::get<0>(v0) == std::get<0>(v1) &&
std::get<1>(v0) == std::get<1>(v1)
);
}
};
struct data
{
int AlertNo;
};
typedef std::unordered_map<const key_t,data,key_hash,key_equal> map_t;
}
enter code here
I want to use this unordered_map created in TableGenerator.cpp file in Analyzer.cpp. I want to keep this unordered_map till the end of the program. For that purpose I want to make unordered_map global. Global seems to be better option rather than sending map as parameter to other function. I use the keyword extern in Analyzer.cpp.
extern map_t obj1; extern data d;
but it still says that undefined reference to obj1 when compiling. Please help me how do I make unorderd_map Global to make use of it in other cpp files. Secondly, is their any other better way to do this thing rather than making map global.