如何在Test.h中管理char數組buffer
?我應該刪除.h文件中的char數組嗎
Test.h
class Test{
public:
Test();
~Test();
char buffer[255];
};
Test.cc
#include "Test.h"
Test::Test()
{
}
Test::~Test()
{
// Do I need to delete/free buffer?
}
我明白,當new
或malloc
使用的內存必須使用delete
或free()
被釋放。
對於Test
的每個實例,堆棧上是否分配了字符數組buffer
,因此不需要刪除?
你永遠不需要刪除任何不是從新返回的東西。 – molbdnilo
請注意,「在標題中」信息不屬於此問題的任何地方。 – LogicStuff