小编Mat*_*att的帖子

unique_ptr,多态类型未被删除

我有一个使用基类的unique_ptrs向量到派生类型存储

std::unique_ptr<std::vector<std::unique_ptr<Variable>>> decisionVariables;
Run Code Online (Sandbox Code Playgroud)

其中Variable是超类,派生类型是Route类.我的问题是,当删除包含decisionVariables的类时,似乎没有删除路由实例.

路由从变量派生:

#ifndef __VARIABLE__
#define __VARIABLE__

/**
 * Interface for decision variables. 
 */

#include <cstring>
#include <ostream>
#include <memory>

class Variable {

    public:
        /**
         * Returns an independent copy of this decision variable.
        *
        * @ret a copy of this decision variable
         */
        virtual std::unique_ptr<Variable> copy () = 0;

        virtual std::string toString () = 0;
};

#endif
Run Code Online (Sandbox Code Playgroud)

路线的头文件:

#ifndef __ROUTE__
#define __ROUTE__

#include <vector>
#include <map>
#include <cstring>
#include <sstream>
#include <ostream>
#include <memory>
#include <set>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ unique-ptr

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

标签 统计

c++ ×1

unique-ptr ×1