public member function
<functional>

std::reference_wrapper::operator type&

operator type&() const noexcept;
轉換為引用
返回被引用物件的引用。

type 是一個描述被引用型別的成員型別(它是類模板引數 T 的別名)。

此函式返回的結果與成員 get 相同。

引數



返回值

被引用的物件。

type 是一個描述被引用型別的成員型別(它是類模板引數 T 的別名)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// reference_wrapper::operator type&
#include <iostream>     // std::cout
#include <functional>   // std::reference_wrapper

int main () {
  int foo;

  std::reference_wrapper<int> wrap (foo);

  static_cast<int&>(wrap) = 10;
  int& bar = wrap;
  ++bar;

  std::cout << foo << '\n';

  return 0;
}

輸出
11


資料競爭

該物件被訪問。
返回的引用可用於訪問或修改該元素。

異常安全

無異常保證:此成員函式從不丟擲異常。

另見