What should I do to delete class object?
Depends on how you create the instance. Objects in automatic, static and thread local storage as well as temporary objects are destroyed automatically. All variables have one of these storage classes.
Dynamic objects must be destroyed explicitly. Typically the ideal way to delete dynamically allocated objects is transfer the ownership to a smart pointer that deletes the pointed object when the smart pointer is destroyed.
City city1 = City("New York", 123, 100000)
This is a variable. As such, the object is destroyed automatically.
Should I change the destructor somehow?
Depends on what responsibilities the class has. Often, the ideal design for a class is one where user defined destructor is not needed.
I'm trying:
city1.~City();
- nothing happens
That is most likely wrong in your case. If you don't create another instance in place of the destroyed one, then the behaviour of the program will be undefined when the variable is destroyed.
delete city1;
or delete[] city1;
- Cannon delete expression of type 'City'
city1
is not a pointer, so it is not something that can be deleted.
delete [city1];
- Expected body of lambda expression
There is no syntax like this in C++.