Hubbry Logo
search
logo

Reference (C++)

logo
Community Hub0 Subscribers
Write something...
Be the first to start a discussion here.
Be the first to start a discussion here.
See all
Reference (C++)

In the C++ programming language, a reference is a simple reference datatype that is less powerful but safer than the pointer type inherited from C. The name C++ reference may cause confusion, as in computer science a reference is a general concept datatype, with pointers and C++ references being specific reference datatype implementations. The definition of a reference in C++ is such that it does not need to exist. It can be implemented as a new name for an existing object (similar to rename keyword in Ada).

The declaration of the form:

where <Type> is a type and <Name> is an identifier is said to define an identifier whose type is lvalue reference to <Type>.

Examples:

Here, r_a and r_b are of type "lvalue reference to int"

foo is a function that returns an "lvalue reference to int"

bar is a function with a reference parameter, which is an "lvalue reference to int"

MyClass is a class with a member which is lvalue reference to int

See all
User Avatar
No comments yet.