C++ Reference Variable Declaration Syntax Reasoning -
all other declaration syntaxes in c++ make lot of sense, examples:
int i; i int
int *i; when i dereferenced, result int
int i[]; when i subscripted, result , int
int *i[]; when i subscriped, result derefrenced, final result int
but when @ syntax reference variables, otherwise consistent reasoning falls apart.
int &i = x; “when address of i taken, result int” makes no sense.
am missing something, or exception apparent reasoning behind other sytaxes? if exception, why syntax chosen?
edit:
this question addresses why & symbol may have been chosen purpose, not whether or not there universally consistent way read declarations different way described above.
once bound, reference becomes alias referent, , cannot distinguished (except decltype). since int& used int is, declaration-follows-usage syntax not work declaring references.
the syntax declaring references pretty straightforward, still. write down declaration corresponding pointer type, replace * used initial dereference & or &&.
Comments
Post a Comment