4
この質問のタイトルに記載されているエラーが発生しました。コードスニペットは次のようになります。それは「読み取り専用」とみなされている理由エラー:読み取り専用ロケーションの割り当て<unnamed> :: g_namesmap
namespace
{
struct myOptVar * g_optvar = 0;
//Variable that stores map of names to index
std::map<std::string, const size_t> g_namesmap;
};
void Optimizations::generate()
{
// free current optvar structure
free(g_optvar);
//clear our names map
g_namesmap.clear();
// create new optvar structure
const unsigned int size = g_items.size();
g_optvar = (struct myOptVar*)calloc(size, sizeof(struct myOptVar));
//copy our data into the optvar struct
size_t i=0;
for (OptParamMapConstIter cit=g_items.begin(); cit != g_items.end(); cit++, i++)
{
OptimizationParameter param((*cit).second);
g_namesmap[(*cit).first] = i; //error occurs here
...
g_namesmapは、無名の名前空間で宣言され、定義されていますか?