Skip to content

Instantly share code, notes, and snippets.

@tmplt
Created July 8, 2014 17:53
Show Gist options
  • Save tmplt/7e62566bb9898fb1706b to your computer and use it in GitHub Desktop.
Save tmplt/7e62566bb9898fb1706b to your computer and use it in GitHub Desktop.
legal and illegal references
int i = 1024, i2 = 2048; // i and i2 are both ints
int &r = i, r2 = i2; // r is a reference bound to i; r2 is an int
int i3 = 1024, &ri = i3; // i3 is and int; ri i a reference bound to i3
int &r3 = i3, &r4 = i2; // both r3 and r4 are references
int &refVal4 = 10; // error: initializer must be an object
double dval = 3.14;
int &refVal4 = dval; // error: initiazlier must be an int object
double dval2 = 4.5345;
double &refVakD = dval2; // a reference may be bound to an object of same type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment