Created
May 3, 2013 08:56
-
-
Save titouanc/5508056 to your computer and use it in GitHub Desktop.
Les pointeurs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Categorie { | |
| public: | |
| int eleves; | |
| Categorie *options; | |
| } | |
| /* Allocation statique: deux objets Categorie sur la stack (voir cours FDO), ba1 et ba2 désignent les objets */ | |
| Categorie ba1, ba2; | |
| /* Allocation dynamique: un objet Categorie sur le heap, un pointeur sur la stack. options désigne l'adresse d'un objet */ | |
| Categorie *options = new Categorie; | |
| ba1.options = options; | |
| ba2.options = options; | |
| delete options; | |
| /* Ici, le pointeur options existe toujours sur la stack, mais plus l'objet vers lequel il pointait. | |
| * Par la même occasion, ba1.options et ba2.options sont maintenant invalides. | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment