#include <iostream>
class TestClass {
public:
TestClass() {
std::cout << "TestClass instantiated\n";
}
~TestClass() {
std::cout << "TestClass destructed\n";
}
void PrintSomething() {
std::cout << "TestClass is printing something\n";
}
};
int main() {
TestClass* tClass = new TestClass();
delete tClass;
tClass = nullptr;
tClass->PrintSomething();
std::cout << "Exiting...\n";
return 0;
}
Result:
TestClass instantiated
TestClass destructed
TestClass is printing something
Exiting...
I thought that trying to print something after the tClass pointer had been set to nullptr would cause a nullpointer exception error, but it prints just fine.