mercredi 3 février 2021

Can I use a name of a deleted pointer?

Is it allowed to use a pointer's name of a pointer once deleted?

This code, for instance, won't compile.

    int hundred = 100;
    int * const finger = &hundred;
    delete finger;

    int * finger = new int; // error: conflicting declaration 'int* finger'

This won't either:

    int hundred = 100;
    int * const finger = &hundred;
    delete finger;

    int finger = 50; // error: conflicting declaration 'int finger'

Aucun commentaire:

Enregistrer un commentaire