what is an Equivalent to this line of code in c++ using the QT library ?

148 Views Asked by At

Given the declarations

   class DBuffer
{
//...
};

typedef QList<DBuffer*> DBuffers;
QList<int> fds;
QMap<int, DBuffers> buffers; 

what does the line of code in the function given below mean.

function()
{
 // what does this line mean? what is "&bufs"

    DBuffers &bufs=buffers[fds[i]];
}
2

There are 2 best solutions below

2
On BEST ANSWER

The & in the declaration indicates this variable is a reference, i.e. bufs doesn't create a new copy of the output but just refers to the object that is assigned to it. Reference types in this context can be thought of as alias for the object they are assigned to.

The RHS of the expression is pretty straight forward: look up an integer off the fds list by the index i, then use this value to get the corresponding Dbuffer from the map.

0
On

It is reference. It means that you create alias of some item from buffer. Changes in alias also reflects in buffer's item