我知道析構函數用於銷燬類中的全局指針,但是我需要它們來銷燬像int或std :: string這樣的正常變量嗎?你需要析構函數來銷燬全局int,float或std :: string變量嗎?
數組如何像int num [2]?
什麼變量類型應該在析構函數中銷燬?
例如:
class myclass
{
public:
myclass()
~myclass()
{
delete num;
delete ar_num;
delete str;
}
private:
int num;
std::string str;
int ar_num[2] = {0,1};
}
您需要閱讀C++的基礎知識。如果你已經有,找到另一個來源,因爲你目前使用的不是很好。 – dandan78