C++: Having trouble using map with a static variable in a class, I get undefined symbol -
this error get
undefined symbols: "config::fmap", referenced from: register_function(unsigned int (*)(unsigned int))in config.o print_config() in shared.o ld: symbol(s) not found collect2: ld returned 1 exit status
config.h
#include <map> #include <boost/preprocessor/stringize.hpp> typedef unsigned int (*fptr_t)(unsigned int); typedef std::map<fptr_t, std::string> function_name_map_type; void register_hash_names(); void register_function(fptr_t funct_pointer); class config { public: static function_name_map_type fmap; };
config.cpp
function_map_t fmap; void register_hash_names() { register_function(sha1); ... } void register_function(fptr_t funct_pointer) { (config::fmap)[funct_pointer] = boost_pp_stringize(funct_pointer); }
shared.cpp error originates from:
std::cout << "\t " << config::fmap[config::current_hash_function] << "\n";
the definition in .cpp should be:
function_map_t config::fmap;
Comments
Post a Comment