Object-Oriented Programming-c++_ lesson 21 references

Source: Internet
Author: User

Data type & alias = object name;

1#include <iostream>2 using namespacestd;3 4 int* F (int*x)5 {6(*x) + +;7     returnx;8 }9 Ten int& G (int&x) One { AX + +; -     returnx; - } the  - intx; -  - int&h () + { -     intQ//!return Q +     returnx; A } at  - voidMain () - { -     intA =0; -Std::cout << a << std::endl;//0 -  inf (&a);//ugly, but clear. -Std::cout << a << std::endl;//1 to  +g (a);//clear, but covert, can modify a -Std::cout << a << std::endl;//2 the  *H () = -;//The return value is a reference, so you can do an lvalue $Std::cout << a << std::endl;//2Panax Notoginseng  -Std::cout << x << Std::endl;// - the  +System"Pause"); A}

You cannot declare a reference reference

You can declare a reference to a pointer, but you cannot declare a pointer-to-variable reference

int & * P;//illegal

int * & P1=p2;//ok

void f (int * & P);

P is a reference that references a pointer to type int

You can declare a pointer to a reference

Arrays without references (array elements cannot be references)

But you can reference an array

Object-Oriented Programming-c++_ lesson 21 references

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.