【发布时间】:2014-04-15 11:48:20
【问题描述】:
我需要帮助来理解为什么 lint 由于 struct 初始化而抱怨下面的代码。
代码运行没有任何问题,或者至少没有任何已知问题
struct MsgKey_t {
int type;
int index;
int signal;
};
typedef std::map< int, std::pair< MsgKey_t*, int* > > MyMap_t;
MyMap_t myMap;
MyMap_t::iterator subKey = myMap.find( 11 );
if ( myMap.end() == subKey )
{
exit(-1);
}
MsgKey_t key = { subKey->second.first->type, subKey->second.first->index, subKey->second.first->signal };
如果我将结构的初始化更改为:
MsgKey_t key;
memcpy( &key, subKey->second.first, sizeof( key ) );
或:
MsgKey_t* pKey = subKey->second.first;
MsgKey_t key = { pKey->type, pKey->index, pKey->signal };
lint 一整天都很开心。
【问题讨论】:
-
糟糕错过了 ;在示例代码中,但在实际代码中这不是问题。
-
m_My和MsgKey是什么? -
错字 m_My 应该是 myMap 而 MsgKey 应该是 MskKey_t