這個是thinking in c++里的題目,counted是自己定義的一個類,要求不用[]釋放陣列的記憶體空間,我想的是用指標加偏移逐個釋放,可是好像不太行
,請問應該怎么操作呢附上完整代碼:
#include<iostream>
using namespace std;
class Counted{
private:
int id;
static int count;
public:
Counted():id(count++)
{
cout<<"the constructor is called.Object id:"<<id<<endl;
}
~Counted()
{
cout<<"the destructor is called. Object id:"<<id<<endl;
}
};
int Counted::count=0;
int main(void)
{
Counted* p=new Counted;
delete p;
Counted* t=new Counted[5];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/44551.html
標籤:新技術前沿
