【发布时间】:2011-05-19 18:57:36
【问题描述】:
我刚刚开始我的容器类,但我已经遇到了问题:
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.
}
};
我收到错误 Container Classes(26467) malloc: *** error for object 0x100100088: pointer being freed was not allocated。我做错了什么?
【问题讨论】:
-
它被称为destructor,就像在破坏中一样。不是解构器。 :)
标签: c++ class pointers memory-leaks destructor