I have two questions regarding the following code:
1. Is this a good practice? If not what is wrong with it?
2. Does the following code create a memory leak or dangling pointers? I am just deleting the double pointer created in the main function and set the element to NULL within the destructor of the class. (Since CLQ does not have the value for the size variable, I only set element = 0).
class CLQ{
public:
int ** element;
void operation(){
// some statements
// element is used as an input, does not change here.
}
~CLQ{
element = 0;
}
}
int main(){
int size = 10;
int ** e = new int *[size]; // e is a size-by-size dynamic array.
for (int i = 0, i<size; i++){
e[i] = new int [size]
}
CLQ myCLQ;
CLQ.element = e;
COQ.operation();
for (int i = 0; i<size; i++){
e[i] = 0;
delete [] e[i];
}
e = 0;
delete [] e;
return 0;
}

New Topic/Question
Reply




MultiQuote




|