I'm trying to create a global map that will map strings to factory functions. This allows me to have a builder function read a key from an ini file, and then pass that ini file with its relevant section to the correct factory function. Here is the code in the header with the global map:
typedef Primitive* (*factory_func_t)(const ::INI&, const std::string&);
const std::map<std::string, factory_func_t> factory_funcs = {
{ SphereFactory::ID, &SphereFactory::create_sphere },
{ QuadFactory::QUAD_ID, &QuadFactory::create_quad },
{ QuadFactory::PQUAD_ID, &QuadFactory::create_pquad }
};
And here is an example of one of those factory classes:
class SphereFactory
{
public:
static const std::string ID;
static Sphere* create_sphere(const ::INI&, const std::string& section);
SphereFactory() = delete;
private:
static const std::string CENTER_KEY;
static const std::string RADIUS_KEY;
};
const std::string SphereFactory::ID = "Sphere";
const std::string SphereFactory::CENTER_KEY = "Center";
const std::string SphereFactory::RADIUS_KEY = "Radius";
All this is giving me an error when compiling:
error: could not convert `{{cg::prim::factory::SphereFactory::ID,
cg::prim::factory::SphereFactory::create_sphere},
{cg::prim::factory::QuadFactory::QUAD_ID,
cg::prim::factory::QuadFactory::create_quad},
{cg::prim::factory::QuadFactory::PQUAD_ID,
cg::prim::factory::QuadFactory::create_pquad}}'
from `<brace-enclosed initializer list>'
to `const std::map<std::basic_string<char>, cg::Primitive* (*)(const INI&,
const std::basic_string<char>&)>'
All of the above code is in the cg::prim::factory namespace, in case that makes a difference. Both Quad and Sphere inherit from Primitive. I'm using g++ -O3 -Wall -Wextra -pedantic -std=c++11 to compile.
Why is this not compiling?