0

我有这个代码:

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 我跟踪了执行情况,在我退出序列化函数之前一切似乎都很好。

有任何想法吗?

4

1 回答 1

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;
于 2012-12-18T23:24:33.760 回答