Syntax and Terminology
The declaration of the form:
where
is a type and
is an identifier whose type is reference to
.
Examples:
int A = 5;
int& rA = A;
extern int& rB;
int& foo ;
void bar (int& rP);
class MyClass { int& m_b; /* ... */ };
int funcX { return 42 ; }; int (&xFunc) = funcX;
Here, rA
and rB
are of type "reference to int
", foo
is a function that returns a "reference to int
", bar
is a function with a reference parameter, which is a "reference to int
". MyClass
is a class
with a member which is reference to int
; funcX
is a function that returns a (non-reference type) int
, and xFunc
is an alias for funcX
.
Types which are of kind "reference to
" are sometimes called reference types. Identifiers which are of reference type are called reference variables. To call them variable, however, is in fact a misnomer, as we will see.
Read more about this topic: Reference (C++)
Famous quotes containing the words syntax and:
“Syntax and vocabulary are overwhelming constraintsthe rules that run us. Language is using us to talkwe think were using the language, but language is doing the thinking, were its slavish agents.”
—Harry Mathews (b. 1930)