Thanks nevermore28, I am clueless in how to proper create a destructor. This is my very first assignment to use pointer, constructor, destructor. I also don't understand what u mean by saying "dynamically allocated variable" .
Dynamically allocated variables are those allocated with new, and are the only ones you should be attempting to delete. As shown above, you did not new your pointer in the constructor (bad) and then attempted to delete it in the destructor.
The above will runs perfectly if you let the dlsplayInteger function out. However, you will get an error "Segmentation fault (core dumped)" if they are included.
The problem lies with your copy constructor. You do not initialize/assign your value variable with some memory location, e.g. value = &FOO; or value = newint; (the latter probably being the the correct one based on your code).
Attempting to dereference a pointer to some random location will most likely cause that segmentation fault.
you are assigning 0 to the value pointed by value which is wrong since you don't have any variable to be pointed by value
Still you are deleting a non-dynamically allocated variable.
you can't just do:
1 2
int *value;
*value = 0; // Wrong !
this is invalid since value does't point to anything, or any memory address and still you are assigning a value to the value pointed by it. Remember that a pointer must first store an address of a variable:
If you want to assign a value to the value pointed by value, you should either use another variable, OR, dynamically allocate value:
1 2 3
int *value = newint; // new returns a memory address to value causing value to now be valid and can be dereferenced
*value = 0; // now this is valid since value now has an address stored on it and can now be dereferenced
delete value; // you should add this in your destructor
based on this, then your constructor definition should be:
1 2 3 4 5
Integer::Integer()
{
value = newint;
*value = 0;
}