C + + Reference review

Source: Internet
Author: User

Reference review
#include <iostream>


using namespace Std;


void Show1 ()
{
cout << "Show1" << Endl;
}
void Show2 ()
{
cout << "Show2" << Endl;
}
void Show3 ()
{
cout << "show3" << Endl;
}


int main ()
{
int one = 1;
int &r1 (one); Lvalue reference, referenced memory entity
int &&r2 (one+1);//rvalue reference, value in reference register
int &&r3 (Move (one));//move can refer to Lvalue as Rvalue
cout << One << "<< R1 <<" "<< R2 <<" "<< R3 << Endl;


int: 1;
int* p (&two);
int* (&AMP;RP) (p);//reference form of a first-level pointer
int** pp (&p);
Int (* * (&AMP;RPP)) (PP); The reference form of the second level pointer
int* && Temp (&two); The address of the variable is the right value, with an rvalue reference
cout << *rp << "<< **rpp << Endl;


void (*a) () (SHOW1); function pointers
A ();
void (*&AMP;AA) () (a); function pointer Reference
AA ();


void (*ra[3]) () {show1, show2, show3}; Array of function pointers on the stack
for (auto I:ra)
{
I ();
}
void (* (&rra) [3]) (RA); Array of function pointers on the reference stack
for (auto I:rra)
{
I ();
}


void (**raa) () = new (void (*[3)) ()) {show1, show2, show3}; Array of function pointers on the heap
for (int i = 0; i < 3; i++)
{
Raa[i] ();
}
void (* * (&AMP;RRAA)) (RAA);
for (int i = 0; i < 3; i++)//reference to the array of function pointers on the heap
{
Rraa[i] ();
}




return 0;
}

C + + Reference review

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.