相当于 c++ 中这行代码的是什么?使用 QT 库?
鉴于声明,
class DBuffer
{
//...
};
typedef QList<DBuffer*> DBuffers;
QList<int> fds;
QMap<int, DBuffers> buffers;
下面给出的函数中的代码行意味着什么。
function()
{
// what does this line mean? what is "&bufs"
DBuffers &bufs=buffers[fds[i]];
}
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]];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
的&声明中的 表示该变量是一个引用,即 bufs 不会创建输出的新副本,而只是引用分配给它的对象。在这种情况下,引用类型可以被认为是它们所分配到的对象的别名。
表达式的 RHS 非常简单:通过索引 i 从 fds 列表中查找整数,然后使用该值从映射中获取相应的 Dbuffer。
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.
是参考。这意味着您从缓冲区创建某些项目的别名。别名的更改也会反映在缓冲区的项目中
It is reference. It means that you create alias of some item from
buffer
. Changes in alias also reflects in buffer's item