小编sfo*_*sen的帖子

帮助我使这段代码异常安全

所以我有这个库代码,请看......

class Thing
{
public:

    class Obj 
    {
     public:
        static const int len = 16;

        explicit Obj(char *str)
        {
            strncpy(str_, str, len);
        }

        virtual void operator()() = 0;

    private:
        char str_[len];
    };

    explicit Thing(vector<Obj*> &objs) : objs_(objs) {}

    ~Thing() {
        for(vector<Obj*>::iterator i = objs_.begin(); i != objs_.end(); ++i) {
            delete *i;
        }
    }

private:
    vector<Obj*> objs_;
}
Run Code Online (Sandbox Code Playgroud)

在我的客户端代码中......

   class FooObj : public Thing::Obj
    {
        virtual void operator()() {
            //do stuff
        }
    }

    class BarObj : public Thing::Obj
    {
        virtual void …
Run Code Online (Sandbox Code Playgroud)

c++ exception smart-pointers container-managed

1
推荐指数
1
解决办法
348
查看次数