What Can Be Referenced?

Any object can be referenced, including user-defined objects. Note that you create a reference to an object, not to a class. You do not write this:

int & rIntRef = int;    // wrong

You must initialize rIntRef to a particular integer, such as this:

int howBig = 200;
int & rIntRef = howBig;

In the same way, you don't initialize a reference to a CAT:

CAT & rCatRef = CAT;   // wrong

You must initialize rCatRef to a particular CAT object:

CAT frisky;
CAT & rCatRef = frisky;

References to objects are used just like the object itself. Member data and methods are accessed using the normal class member access operator (.), and just as with the built-in types, the reference acts as an alias to the object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.60.232