-2

eg:

//The standard method
int x=10;
int &y=x;

I tried

int &y;
y=x;

It didn't work, I am looking for another way to run it.

SHR
  • 7,940
  • 9
  • 38
  • 57
Deadman
  • 1
  • 3

2 Answers2

0

You can't declare a reference without initialising it. Maybe what you want is a pointer.

swang
  • 5,157
  • 5
  • 33
  • 55
0

There are 2 types of reference:

rvalue - refer to persistent objects whose value you want to change lvalue - refer to temporary objects whose value you want to change

lvalue Example:

int num = 1;
int& r1 {num};
int& r2; // error: need initialization
int& r2 = num;
int* p = #
int& r3 = *p;

rvalue Example:

int&& rr1{ int() }; // temporary
int&& rr2{ 2 }; // temporary
dspfnder
  • 1,135
  • 1
  • 8
  • 13