我有一个关于性病不确定性::地图上C++:的std ::地图问题,关于C++
我这样做,加载链接库(的.so)C_ConfigurationLibrary
一个对象C_Configuration
。
该C_Configuration
类有一个std::map
和The C_ConfigurationLibrary
有一个方法,初始化std::map
。
如果我接触到std::map
从C_Configuration
有 “for” 循环:
std::map<const char*, const char*>::iterator l_item;
for(l_item = m_configuration_map.begin();
l_item != m_configuration.end();
l_item++)
这是可行的;
但是,如果使用:
m_configuration[VALUE_KEY] // the value is NULL
这也不行;
我的代码:
C_Configuration::C_Configuration()
{
m_configuration = LoadLibrary(); // load the linked library (.so)
if(m_configuration != NULL)
{
// DEBUG
LOG_DEBUG("Loading Key from plugin...");
m_configuration->LoadKeys(m_configuration_map);
std::map <const char*, const char*>::iterator l_item;
for (l_item = l_configuration_map.begin();
l_item != l_configuration_map.end();
l_item++)
{
//THIS IS OK
}
m_configuration_map[FIRST_KEY] // THIS IS NOT OK
}
}
void C_ConfigLibrary::LoadKeys(std::map<const char*, const char*>& p_configuration_map)
{
// DEBUG
LOG_DEBUG("Loading Keys...");
p_configuration_map.insert (std::make_pair<const char*, const char*>(FIRST_KEY, FIRST_VALUE));
// DEBUG
LOG_DEBUG("Loaded Key DBUS used: %s",m_dbus_used.c_str());
p_configuration_map.insert (std::make_pair<const char*, const char*>(SECOND_KEY,SECOND_VALUE));
}
你能帮助我吗?
感谢这么多
“这不好”是什么意思?这是返回?它会崩溃吗?你也有2个左边的“太多”,这使得代码不太直观。 –
您正在使用'm_configuration [VALUE_KEY]',但您尚未将'VALUE_KEY'插入地图。这是问题吗? – Naveen
“这是不好的”意味着返回值是“NULL”,源代码是一个示例,如果有一些错误为“}”,请忽略它们,代码编译并运行。我认为这是一个内存访问问题,取决于std :: map。 – Gianfranco