代码片段如下:
CopyConfigBase *copyConfig = CopyConfigManager::getInstance().get( pUser->copyid); if ( !copyConfig) { return true; } Map* map = MapManager::getInstance().loadMap(copyConfig->mapid); if ( !map ) { return true; } RoleDefineVector* ndv = &(copyConfig->roleDefine); //map->loadRole(copyConfig->roleDefine); HangCopy* copy= new HangCopy( copyConfig, map);
调试结果如下:
(gdb) p copyConfig $3 = (CopyConfigBase *) 0x1f17fe8 (gdb) p &(copyConfig->roleDefine) $4 = (RoleDefineVector *) 0x1f18030 (gdb) n 299 Map* map = MapManager::getInstance().loadMap(copyConfig->mapid); (gdb) n 300 if ( !map ) { (gdb) n 303 RoleDefineVector* ndv = &(copyConfig->roleDefine); (gdb) p &(copyConfig->roleDefine) $5 = (RoleDefineVector *) 0x1f18030 (gdb) n 305 HangCopy* copy= new HangCopy( copyConfig, map); (gdb) p ndv $6 = (RoleDefineVector *) 0x1f1802c (gdb) p *ndv $7 = std::vector of length 38654705664, capacity 68719476736 = {Cannot access memory at address 0x1f1948000000000 (gdb) n 306 if ( copy ) {
为什么给ndv变量赋值后ndv的值为 0x1f1802c ,而不是 0x1f18030。copyConfig->roleDefine中的vector的值是正确。谢谢谁能解答下。