I am making a class for dynamiclly allocated variables in c++ mostly for learning. And I ran into a bug, where when I delete the class, calling the deconstructor un-allocating the memory, and than deleteing the class, it seems to delete all my code after that as well, why is this?
Here you have some code from the program:
Destructor:
k_int::~k_int() {
delete[] Integer;
}
Constructor:
k_int::k_int(int value, bool BooleanConstant = false) {
Integer = new (nothrow) int[1];
constant = BooleanConstant; // if you wanna make your allocated space constant
if (Integer == nullptr) {
cout << STD_MEM_ERR << endl;
exit(0);
}
Integer[1] = value;
}
Main:
int main() {
k_int a(123);
a.print();// I did not show the source code for this
delete &a;
cout << "Test after delete" << endl;// Does not run, nothing does :(
}
EDIT:
The reason I wanna delete variables is that I don't wanna have them running for the rest of the program, that it won't exist after i close my program does not help.