首页 \ 问答 \ 引用临时变量的静态引用(static reference referring to temporary variable)

引用临时变量的静态引用(static reference referring to temporary variable)

#include <iostream>

int getID ( int k ) {
    static int& r = k;
    return r++;
}

int main()
{
    int a = getID ( 10 );
    int b = getID ( 10 );
    std::cout << "a = " << a << ", b = " << b  << std::endl;
    return 0;
}

我不明白为什么要编译这些代码。

  1. 一个静态引用如何引用一个局部变量k,它将在函数调用结束时消失)。
  2. 在第二次调用时,我们用新变量重新初始化静态引用。 请解释一下这里发生了什么,静态REFERENCE是如何被“重新定义”的(我想我不理解对方法内部静态变量的引用的含义)。

#include <iostream>

int getID ( int k ) {
    static int& r = k;
    return r++;
}

int main()
{
    int a = getID ( 10 );
    int b = getID ( 10 );
    std::cout << "a = " << a << ", b = " << b  << std::endl;
    return 0;
}

I don't understand why this code compiles.

  1. How is it possible for a static reference to refer to a local variable k, which will disappear in the end of the function call).
  2. On the second call we reinitialize the static reference with a new variable. Please explain what happens here, how come static REFERENCE can be "redefined" (i guess that i don't understand the meaning of a reference to a static variable inside a method).

原文:https://stackoverflow.com/questions/32592616
更新时间:2023-11-22 08:11

最满意答案

.ngx-datatable.bootstrap:not(.cell-selection) .datatable-body-row:hover, .ngx-
datatable.material:not(.cell-selection) .datatable-body-row:hover .datatable-
row-group {
    background: red;
}

这工作。


.ngx-datatable.bootstrap:not(.cell-selection) .datatable-body-row:hover,
.ngx-datatable.material:not(.cell-selection) .datatable-body-row:hover .datatable-row-group
{ 
   background: red;
}

This works.

相关问答

更多
  • 首先关闭ngx-datatable了 checkboxable:布尔值 指示列是否应显示用于选择的复选框组件。 仅在选择模式为复选框时适用。 所以你可以告诉它你的列应该是复选框。 其次,如果您确实需要一个带有conponent的自定义模板,则需要创建一个有效的组件,然后可以将其包含在要在单元格中使用的模板中: