Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/165.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;std::reference\u包装器如何隐式转换为reference?_C++_Reference_C++11_Implicit Conversion_Reference Wrapper - Fatal编程技术网

C++ C++;std::reference\u包装器如何隐式转换为reference?

C++ C++;std::reference\u包装器如何隐式转换为reference?,c++,reference,c++11,implicit-conversion,reference-wrapper,C++,Reference,C++11,Implicit Conversion,Reference Wrapper,我最近开始使用std::reference\u包装器类。在替换基元引用的某些用法时,我注意到我不必使用get()函数将引用包装器作为参数传递给采用普通引用的函数 void foo(const T& a); //... T obj; std::reference_wrapper<const T> ref(obj); foo(ref); //works! //foo(ref.get()); also works, but I expected that it would be

我最近开始使用
std::reference\u包装器
类。在替换基元引用的某些用法时,我注意到我不必使用
get()
函数将引用包装器作为参数传递给采用普通引用的函数

void foo(const T& a);
//...
T obj;
std::reference_wrapper<const T> ref(obj);
foo(ref);  //works!
//foo(ref.get()); also works, but I expected that it would be required
void foo(const T&a);
//...
T-obj;
标准:参考包装参考(obj);
foo(ref)//作品
//foo(ref.get());也可以,但我认为这是必需的

std::reference\u包装器
在传递到函数时如何隐式转换为基元引用?

它重载此转换运算符:

operator T& () const;

参考文件包括(§20.8.3):

这是一个转换运算符,因为它没有指定为
显式
,所以它允许从
引用包装器
隐式转换为
t&

// access
operator T& () const noexcept;