user834850
user834850

Reputation:

What means that kind of declaration in c++?

What does this kind of declaration mean in c++?

CSomething & SOMETHING = m_vSOMETHING[m_iSOMETHING];

Upvotes: 4

Views: 152

Answers (2)

Soren
Soren

Reputation: 14688

It is a reference variable which is initialized to point to the specified cell in m_vSOMETHING

So a declaration of

int &reftotable = table[42];

Will produce reftotable as a variable which reference cell 42 in the table, similar to what

int *pointertocell = &table[42];

would do. In the first case with the reference you can assign reftotable like it was a normal variable

reftotable = 37;

where in the other case you will have to do

*pointertocell = 37;

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

Upvotes: 8

Jim Deville
Jim Deville

Reputation: 10662

SOMETHING is a reference to a CSomething and you are assigning the m_iSOMETHINGth element of m_vSOMETHING to that reference

Upvotes: 1

Related Questions