我有这段代码:
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我跟踪执行,一切似乎都没问题,直到我退出序列化函数。
有什么想法吗?
答案 0 :(得分:1)
尝试:
if ((*iter) == NULL)
{ throw std::runtime_error("Was not expecting that");
}
// Or use some other technique to compensate for a NULL pointer.
serializedObjectList << **iter;