vendredi 29 mai 2015

Brace-enclosed initializer list must be initialized by constructor

I would like to create a type of MoleculeTypes as follow:

const std::string Molecule::REVENZ = "REVENZ"; //!< Reversible Enzyme
const std::string Molecule::IRRENZ = "IRRENZ"; //!< Irreversible Enzyme
const std::string Molecule::INTMET = "INTMET"; //!< Internal Metabolite
const std::string Molecule::EXTMET = "EXTMET"; //!< External Metabolite
const std::string Molecule::METABOLITE = "METABOLITE"; //!< Metabolite
const std::string Molecule::REACTION = "REACTION"; //!< Reaction
const std::string Molecule::REACTANT = "REACTANT"; //!< Reactant
const std::string Molecule::PRODUCT = "PRODUCT"; //!< Product

std::map<std::string, const int> MoleculeTypes =
{
    {Molecule::REVENZ,1},
    {Molecule::IRRENZ,2},
    {Molecule::INTMET,3},
    {Molecule::EXTMET,4},
    {Molecule::METABOLITE,5},
    {Molecule::REACTION,6},
    {Molecule::PRODUCT,7},
    {Molecule::REACTANT,8}
};

If I compile the program by using Makefile, it works well. But it throws the following error when I build it in Qt Creator. C++11 is enabled too.

  • bio.cpp:26: error: in C++98 'MoleculeTypes' must be initialized by constructor, not by '{...}'
  • bio.cpp:26: error: could not convert '{{Molecule::REVENZ, 1}, {Molecule::IRRENZ, 2}, {Molecule::INTMET, 3}, {Molecule::EXTMET, 4}, {Molecule::METABOLITE, 5}, {Molecule::REACTION, 6}, {Molecule::PRODUCT, 7}, {Molecule::REACTANT, 8}}' from '' to 'std::map, const int>' };

Aucun commentaire:

Enregistrer un commentaire