在我的应用程序中,我使用C++代码complie.There是xxx.cpp中的一个函数,如下所示:
void Cache::addRequest(SREQUEST req)
{
m_reqs.push_back(req);
}当我的应用程序调用这个函数时,它会抛出运行时错误:
Fatal signal 7 (SIGBUS), code 1, fault addr 0xb8509ce1 in tid 32190 (com.example)属性"m_reqs“是一个向量对象,它在头文件(xxx.h)中显示:
vector<SREQUEST> m_reqs;
struct SREQUEST
{
SREQUEST()
{
code = "";
oldLen = 0;
}
TimeRound tr; // enum(int type)
std::string code;
int oldLen;
};我在类"Cache“中使用单例模式。
Cache* Cache::getInstance()
{
static Cache* _instance;
// init
if (_instance == NULL)
{
_instance = new Cache();
}
// return the pointer
return _instance;
}错误只会被真实的手机抛出,而不是模拟器。我找到了解决方案,但我不知道是什么导致了这个问题。我的意思是,它总是出现在:
SREQUEST req;
req.code = "123";
req.tr = 1;
req.oldLen = 0;
Cache::getInstance()->addRequest(req); // cause error我把它修复得像:
typedef vector<SREQUEST> VEC_SREQUEST;
VEC_SREQUEST* Cache::getVector()
{
if(v_reqs == 0) // int type
{
vector<SREQUEST>* TEMP = new vector<SREQUEST>();
void* x = (void*)TEMP;
v_reqs = (int)x;
}
void* temp = (void*)v_reqs;
VEC_SREQUEST* res = ((VEC_SREQUEST*)temp);
return res;
}
void Cache::addRequest(SREQUEST req)
{
VEC_SREQUEST* vec = getVector();
vec->push_back(req);
}在我的cpp中,我广泛地使用了代码“xxx.push_back(某物)”。使用这个解决方案需要大量时间的工作。
那么是什么原因导致"xxx.push_back“不能工作呢?而如果没有大的修改,该如何修复呢?
发布于 2016-04-13 10:26:23
我知道原因了。
首先对xxx.h file.The函数语句底部的向量对象进行去核。
换位了,一切都好!
https://stackoverflow.com/questions/36544330
复制相似问题