从不兼容的类型分配给 DWORD nullptr_t
Assigning to DWORD from incompatible type nullptr_t
尽管阅读了几个互联网和论坛 questions/answers 我还不明白为什么以下代码会生成“来自不兼容指针类型的赋值”错误。
void ITEM_MANAGER::FindItemMonster(LPCHARACTER ch, std::string name_item){
DWORD iGasite = 1;
int iIndex = 0;
itertype(m_map_pkDropItemGroup) it;
for (std::map<DWORD, CDropItemGroup*>::iterator it = m_map_pkDropItemGroup.begin(); it != m_map_pkDropItemGroup.end(); it++)
{
if (it != m_map_pkDropItemGroup.end())
{
__typeof(it->second->GetVector()) v = it->second->GetVector();
for (DWORD i = 0; i < v.size(); ++i)
{
TItemTable* Titem = ITEM_MANAGER::instance().GetTable(v[i].dwVnum);
bool nume = (name_item.length() ? strstr(Titem->szLocaleName, name_item.c_str()) != NULL : true);
const CMob* pMob = CMobManager::instance().Get(it->first);
std::string name_monster(pMob->m_table.szLocaleName);
if (nume)
{
DWORD mob_vnum = pMob->m_table.dwVnum;
int iFounded = SECTREE_MANAGER::instance().GetMonsterCountSpawned(mob_vnum);
std::string nume_item(Titem->szLocaleName);
boost::algorithm::replace_all(nume_item, " ", "_");
std::string nume_mob(name_monster.c_str());
boost::algorithm::replace_all(nume_mob, " ", "_");
ch->ChatPacket(CHAT_TYPE_COMMAND, "searched_item %d %s %s %d %d %d %d %d", iIndex, nume_item.c_str(), nume_mob.c_str(), v[i].dwVnum, v[i].iCount, v[i].iProcent, iFounded, mob_vnum);
iIndex = iIndex + 1;
iGasite = iGasite + 1;
}
}
}
}
ch->ChatPacket(CHAT_TYPE_COMMAND, "searched_item_count %d", iGasite);
iGasite = iGasite = NULL;
iIndex = iIndex = NULL;
}
编译器错误:
item_manager.cpp:1136:22: error: assigning to 'DWORD' (aka 'unsigned int') from incompatible type
'nullptr_t'
iGasite = iGasite = NULL;
^~~~
/usr/include/sys/_null.h:35:14: note: expanded from macro 'NULL'
#define NULL nullptr
^~~~~~~
item_manager.cpp:1137:20: error: assigning to 'int' from incompatible type 'nullptr_t'
iIndex = iIndex = NULL;
^~~~
/usr/include/sys/_null.h:35:14: note: expanded from macro 'NULL'
#define NULL nullptr
^~~~~~~
2 errors generated.
您正在使用 NULL
作为零的常量,而它被定义为:
// in /usr/include/sys/_null.h:35:14
#define NULL nullptr
从 C++11 开始,这是标准定义。
nullptr
的类型是std::nullptr_t
,不是整数,所以不能赋值给DWORD iGasite
,unsigned int
.
简单地删除所有使用 NULL
的地方,并适当地用 0
或 nullptr
替换它。
尽管阅读了几个互联网和论坛 questions/answers 我还不明白为什么以下代码会生成“来自不兼容指针类型的赋值”错误。
void ITEM_MANAGER::FindItemMonster(LPCHARACTER ch, std::string name_item){
DWORD iGasite = 1;
int iIndex = 0;
itertype(m_map_pkDropItemGroup) it;
for (std::map<DWORD, CDropItemGroup*>::iterator it = m_map_pkDropItemGroup.begin(); it != m_map_pkDropItemGroup.end(); it++)
{
if (it != m_map_pkDropItemGroup.end())
{
__typeof(it->second->GetVector()) v = it->second->GetVector();
for (DWORD i = 0; i < v.size(); ++i)
{
TItemTable* Titem = ITEM_MANAGER::instance().GetTable(v[i].dwVnum);
bool nume = (name_item.length() ? strstr(Titem->szLocaleName, name_item.c_str()) != NULL : true);
const CMob* pMob = CMobManager::instance().Get(it->first);
std::string name_monster(pMob->m_table.szLocaleName);
if (nume)
{
DWORD mob_vnum = pMob->m_table.dwVnum;
int iFounded = SECTREE_MANAGER::instance().GetMonsterCountSpawned(mob_vnum);
std::string nume_item(Titem->szLocaleName);
boost::algorithm::replace_all(nume_item, " ", "_");
std::string nume_mob(name_monster.c_str());
boost::algorithm::replace_all(nume_mob, " ", "_");
ch->ChatPacket(CHAT_TYPE_COMMAND, "searched_item %d %s %s %d %d %d %d %d", iIndex, nume_item.c_str(), nume_mob.c_str(), v[i].dwVnum, v[i].iCount, v[i].iProcent, iFounded, mob_vnum);
iIndex = iIndex + 1;
iGasite = iGasite + 1;
}
}
}
}
ch->ChatPacket(CHAT_TYPE_COMMAND, "searched_item_count %d", iGasite);
iGasite = iGasite = NULL;
iIndex = iIndex = NULL;
}
编译器错误:
item_manager.cpp:1136:22: error: assigning to 'DWORD' (aka 'unsigned int') from incompatible type
'nullptr_t'
iGasite = iGasite = NULL;
^~~~
/usr/include/sys/_null.h:35:14: note: expanded from macro 'NULL'
#define NULL nullptr
^~~~~~~
item_manager.cpp:1137:20: error: assigning to 'int' from incompatible type 'nullptr_t'
iIndex = iIndex = NULL;
^~~~
/usr/include/sys/_null.h:35:14: note: expanded from macro 'NULL'
#define NULL nullptr
^~~~~~~
2 errors generated.
您正在使用 NULL
作为零的常量,而它被定义为:
// in /usr/include/sys/_null.h:35:14
#define NULL nullptr
从 C++11 开始,这是标准定义。
nullptr
的类型是std::nullptr_t
,不是整数,所以不能赋值给DWORD iGasite
,unsigned int
.
简单地删除所有使用 NULL
的地方,并适当地用 0
或 nullptr
替换它。