خرید بک لینک

Vote count: 0

How do I manually delete an instance of a class?

Please note that this is not a complex question about scope, how objects are managed on the stack, new'd and destructed on the heap, or managed with smart pointers. I just want to dissolve the instance and re-instantiate it.

Example:

#include <iostream>
#include <cstring>

class Cheese {
private:
    string brand;
    float cost;
public:
    Cheese(); // Default constructor
    Cheese(string brand, float cost); // Parametrized constructor
    Cheese(const Cheese & rhs); // Copy construtor
    ~Cheese(); // Destructor
    // etc... other useful stuff follows
}

int main() {
    Cheese cheddar("Cabot Clothbound", 8.99);
    Cheese swiss("Jarlsberg", 4.99);

    eradicate swiss; 
    // fairly certain that "eradicate" is not a keyword,
    // but I am trying to make a point. Trash this instance!

    Cheese swiss("Gruyère",5.99);
    // re-instantiate swiss

    cout << "";
    retu 0;
}

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 5 فروردين 1395 ساعت: 10:09

صفحه بندی