小编Sou*_*rav的帖子

C++错误:在移动构造函数中使用已删除的函数

#include<iostream>
#include<vector>

class Container {
    int * m_Data;
public:
    Container() {
        //Allocate an array of 20 int on heap
        m_Data = new int[20];

        std::cout << "Constructor: Allocation 20 int" << std::endl;
    }

    ~Container() {
        if (m_Data) {
            delete[] m_Data;
            m_Data = NULL;
        }
        std::cout << "Destructor called" << std::endl;
    }

    Container(const Container & obj) {
        //Allocate an array of 20 int on heap
        m_Data = new int[20];

        //Copy the data from passed object
        for (int i = 0; i < …
Run Code Online (Sandbox Code Playgroud)

c++ constructor move-semantics

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

标签 统计

c++ ×1

constructor ×1

move-semantics ×1