类析构函数中的错误

Max*_*xpm 3 c++ pointers destructor memory-leaks class

我刚刚开始我的容器类,我已经遇到了问题:

class Container
{
    private:

    string* BasePointer; // The starting pointer.
    unsigned int Capacity; // The number of values the container can hold.

    public:

    Container() // Default constructor.
    {
        Capacity = 1;
        BasePointer = new string[Capacity];
    }

    ~Container() // Destructor.
    {
        delete BasePointer; // Delete the container to prevent memory leaking.
    }
};
Run Code Online (Sandbox Code Playgroud)

我收到了错误Container Classes(26467) malloc: *** error for object 0x100100088: pointer being freed was not allocated.我做错了什么?

Nik*_*sov 7

XXX ptr = new XXX[size]应与数组版本进行匹配delete [] ptr,而不是常规的delete.

阅读C++中的免费商店管理,正如詹姆斯提醒我们的那样 - 在这样的情况下遵循三条规则.