xml文件如下:
<?xml version="1.0" encoding="utf-8"?> logo 测试logo guanKa 关卡 deFen 得分:类如下:
#include “ZhongWenDict.h”
ZhongWenDict* ZhongWenDict::myDict = NULL;
ZhongWenDict::ZhongWenDict()
{
dict = CCDictionary::createWithContentsOfFile(“dict.xml”);
}
ZhongWenDict::~ZhongWenDict()
{
}
ZhongWenDict* ZhongWenDict::GetDictInstance()
{
if (!myDict)
{
myDict = new ZhongWenDict;
}
return myDict;
}
void ZhongWenDict::GetValueByKey(char* key, char* value)
{
// const char* val = ((CCString*)dict->objectForKey(key))->_string.c_str();
strcpy(value, ((CCString*)dict->objectForKey(key))->_string.c_str());
}
调用点:
A类中:
char logo;
memset(logo, 0, 64);
ZhongWenDict::GetDictInstance()->GetValueByKey(“logo”, logo);
B类中:
char value;
memset(value, 0, 64);
ZhongWenDict::GetDictInstance()->GetValueByKey(“logo”, value);
A类中能调用成功,B类会抛异常:
Assert failed: this dictionary does not use string as key.
Assertion failed!
Program: …proj\DaDiSHu\proj.win32\Debug.win32\libcocos2d.dll
File: …\deprecated\CCDictionary.cpp
Line: 168
Expression: _dictType == kDictStr
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
(Press Retry to debug the application - JIT must be enabled)线程 0x2d04 已退出,返回值为 3 (0x3)。