D
desktop
I have this class:
class MyArray {
public:
MyArray(int a) : data(new int[a]){}
~MyArray() {delete[] data;}
int& operator()(int a){
return data[a];
}
int operator()(int a) const{
return data[a];
}
private:
int* data;
};
int main() {
MyArray myarr(5);
return 0;
}
But when are the destructor called?
class MyArray {
public:
MyArray(int a) : data(new int[a]){}
~MyArray() {delete[] data;}
int& operator()(int a){
return data[a];
}
int operator()(int a) const{
return data[a];
}
private:
int* data;
};
int main() {
MyArray myarr(5);
return 0;
}
But when are the destructor called?