Usually when comes to pointers (e.g int pointer) it needs to know the size.
Example:
int arr[4] = {1,2,3,4};
int *p1 = arr; // this is pointer arithmetic of 1 byte
int (*p2)[4] = &arr; // this is pointer arithmetic of 4 bytes
For the class example below which is permitted ..
class Link_screen {
Screen window;
Link_screen *next;
Link_screen *prev;
};
Why is *next allowed when class Link_screen not defined?
I know from C++ Primer 5th solution that it's possible because a class is considered declared (but not defined) as soon as it's class name appears. Understood. But still, the storage is not known yet. You can see from the above int pointer example that they all needs the storage size. It makes sense that a pointer when defined needs to know the storage it needs. One clear example needed is for pointer arithmetic.
Thanks for help.
Aucun commentaire:
Enregistrer un commentaire