list.clear()上的Segfault

时间:2014-03-01 00:28:32

标签: c++ list boost stl segmentation-fault

我有一个继承列表的对象(当前boost::ptr_list<Command>,尽管std::list<Command *>抛出了完全相同的错误),如下所示:

class Command : public Serializable
{
protected:
    bool queued;
    Selector unit;
    long double time;

public:
    Command(Selector unit, bool queued, long double time) :unit(unit)
    {
        this->queued = queued;
        this->time = time;
    };

    bool getQueued(){ return queued; };
    Selector getUnit(){ return unit; };

    virtual void issue(World * world) = 0;
};

class CommandList : public Serializable, public boost::ptr_list<Command>
{
public:
    CommandList(){};
    CommandList(ptree serial) { deserialize(serial); };

    virtual void issue(World * world);

    ptree serialize();
    void deserialize(ptree serial);

    static CommandList * deserializedCommandList(ptree serial){ return new CommandList(serial); }
    static Serializable * returnDeserialized(ptree serial){return deserializedCommandList(serial);}
};

我创建了一个所谓对象的实例,如下所示:

class Client
{
public:
    CommandList commandList;
....
}

以后,尝试在另一个函数中调用它的两个函数:

void Client::Networking::clientNetworkThing(Client * client)
{
    ...
        string out = ptreeToString(client->commandList.serialize());
        cout << "out: " << out;
    ...
        client->commandList.clear();
    ...
}

第一个成功,但程序在调用clear()的行上崩溃,visual studio报告错误:

"Unhandled exception at 0x638A3703 (msvcr120d.dll) in moba_source.exe: 0xC0000005:
Access violation writing location 0x008EB7F0."

在监视窗格中,它说(指的是commandList):

a nonstatic member reference must be relative to a specific object

0 个答案:

没有答案