What does such a declaration mean in C ++?

What does this declaration mean in C ++?

CSomething & SOMETHING = m_vSOMETHING[m_iSOMETHING]; 
+4
source share
2 answers

This is a reference variable that is initialized to point to the specified cell in m_vSOMETHING

So the announcement

 int &reftotable = table[42]; 

Will produce reftotable as a variable that refers to cell 42 in the table, similar to what

 int *pointertocell = &table[42]; 

. In the first case with a link, you can assign reftotable, as it was a regular variable

 reftotable = 37; 

where otherwise you have to do

 *pointertocell = 37; 

to do the same, that is, in both cases, the table [42] will contain the value 37 after the appointment.

+8
source

SOMETHING is a link to CSomething , and you assign the m_iSOMETHING th element to m_vSOMETHING this link

+1
source

All Articles