Hello stackOverflow friends, I am studying OOP and the following problem arose: I have a class with two attributes, one of type string and the other of type int, when I create an object I show its data on the screen and then I call the destructor. To confirm the deletion of the object, I call the method again to show the data of the object and it turns out that only the information of the string is deleted. I don't know if I'm missing something with the destructor or if I'm just doing it all wrong. Here the code:
#include<iostream>
#include<cstdlib>
using namespace std;
class Persona
{
public:
Persona(string,int);
~Persona();
void mostrarPersona();
private:
string nombre;
int edad;
};
Persona::Persona(string _nombre, int _edad)
{
nombre = _nombre;
edad = _edad;
}
Persona::~Persona()
{
}
void Persona::mostrarPersona()
{
cout << "\tNombre: " << nombre << endl;
cout << "\tEdad: " << edad << endl;
}
int main() {
system("color 1F");
Persona p1("Luis Miguel", 45);
p1.mostrarPersona();
p1.~Persona();
p1.mostrarPersona();
system("pause");
return 0;
}