CCDirectionary 的使用问题

cocos2d-x debug info
WhiteAndBlack: …/cocoa/CCDictionary.cpp:218: void cocos2d::CCDictionary::setObject(cocos2d::CCObject*, const string&): Assertion `m_eDictType == kCCDictStr’ failed.
Aborted (core dumped)

我箱把精灵对象添加到字典里然后以字符串当做key结果报这个错了,我看了一下源码
我使用create创建
create源码如下:
CCDictionary* CCDictionary::create()
{
CCDictionary* pRet = new CCDictionary();
if (pRet != NULL)
{
pRet->autorelease();
}
return pRet;
}

他会调用构造函数:

CCDictionary::CCDictionary()
: m_pElements(NULL)
, m_eDictType(kCCDictUnknown)
{

}

注意这时他把m_eDictType 初始化为kCCDictUnknown
这时我调用setobject 源码如下下:

void CCDictionary::setObject(CCObject* pObject, const std::string& key)
{
CCAssert(key.length() > 0 && pObject != NULL, “Invalid Argument!”);
if (m_eDictType == kCCDictUnknown)
{
m_eDictType = kCCDictStr;
}

CCAssert(m_eDictType == kCCDictStr, "this dictionary doesn't use string as key.");

CCDictElement *pElement = NULL;
HASH_FIND_STR(m_pElements, key.c_str(), pElement);
if (pElement == NULL)
{
    setObjectUnSafe(pObject, key);
}
else if (pElement->m_pObject != pObject)
{
    CCObject* pTmpObj = pElement->m_pObject;
    pTmpObj->retain();
    removeObjectForElememt(pElement);
    setObjectUnSafe(pObject, key);
    pTmpObj->release();
}

}

CCAssert(m_eDictType == kCCDictStr, “this dictionary doesn’t use string as key.”);
代码里的这句话总能成立呀。

不知道楼主解决了没

CCAssert的意义在于, 如果第一个参数返回false, 则崩第二个参数的错误, 你完全没读懂意思