我尝试从 CCDictionary allKeys() 方法中获取 std 字符串键,但是当我尝试从 CCArray 中获取键时,我得到了堆栈,这就是我所拥有的:
CCArray* pAllkeys = CCArray::create();
pAllkeys->addObjectsFromArray(GameSingleTone::getInstance()->getGemsDictionary()->allKeys());
pAllkeys->retain();
在这里我尝试获取密钥,但我得到编译错误:
int gemsToRemoveCount = pAllkeys ->count();
for(int i=0;i<gemsToRemoveCount;i++)
{
std::string gemKey = pAllkeys->objectAtIndex(i);
}
这是我得到的编译错误:4
IntelliSense: no suitable constructor exists to convert from "cocos2d::CCObject *" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>"
挖掘标题后 更新找到了解决方案
CCString* name = dynamic_cast<CCString*>(pAllkeys->objectAtIndex(i));
std::string newkey = name->m_sString;