gpt4 book ai didi

c++ - std::string 中的非法指令

转载 作者:行者123 更新时间:2023-11-28 07:50:20 24 4
gpt4 key购买 nike

我有这个代码:

class USerializer {
public:
template<typename T>
static std::string serialize(std::list<T*> listOfObjectToSerialize)
{
// stringstream containing serialized Objects
std::stringstream serializedObjectList;

typename std::list<T*>::iterator iter;

// serialize Objects
for (iter = listOfObjectToSerialize.begin(); iter != listOfObjectToSerialize.end(); ++iter)
{
// Class delimiter
serializedObjectList << '+'<< endl;

// Need to serialise the class itself, and not the pointer to it!
serializedObjectList << **iter;
}

return serializedObjectList.str();
}
}

然后我像这样使用这个方法:

std::string serializedAlarmInfo = USerializer::serialize<CcAlarm::AlarmInfo>(getActiveAlarms());

我收到 SIGILL 错误:

Program received signal SIGILL, Illegal instruction.

我使用 gdb 跟踪了执行过程,一切似乎都很好,直到我退出序列化函数。

有什么想法吗?

最佳答案

尝试:

if ((*iter) == NULL)
{ throw std::runtime_error("Was not expecting that");
}
// Or use some other technique to compensate for a NULL pointer.
serializedObjectList << **iter;

关于c++ - std::string 中的非法指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13943045/

24 4 0
文章推荐: javascript - 从
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com