隐式对象参数和此指针 [英] implicit object parameter and this pointer

查看:102
本文介绍了隐式对象参数和此指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于

const,volatile和ref限定成员函数

const-, volatile-, and ref-qualified member functions

它被提及:

可以在没有ref限定符的情况下声明非静态成员函数, 带有左值ref限定符(参数列表后的标记&)或 右值ref限定符(参数列表后的标记&&). 在重载解决期间,非静态CV限定的成员函数 X类的处理方式如下:

A non-static member function can be declared with no ref-qualifier, with an lvalue ref-qualifier (the token & after the parameter list) or the rvalue ref-qualifier (the token && after the parameter list). During overload resolution, non-static cv-qualified member function of class X is treated as follows:

没有ref限定词:隐式对象参数具有对cv限定的X的左值类型引用,并且还可以绑定右值隐式对象参数

no ref-qualifier: the implicit object parameter has type lvalue reference to cv-qualified X and is additionally allowed to bind rvalue implied object argument

左值引用限定符:隐式对象参数的类型为左值 引用符合简历的X

lvalue ref-qualifier: the implicit object parameter has type lvalue reference to cv-qualified X

rvalue ref-qualifier:隐式对象参数的类型为rvalue 引用符合简历的X

rvalue ref-qualifier: the implicit object parameter has type rvalue reference to cv-qualified X

注意:与cv-qualification不同,ref-qualification不会更改 this指针的属性:在右值ref限定的范围内 函数,*这仍然是一个左值表达式.

Note: unlike cv-qualification, ref-qualification does not change the properties of the this pointer: within a rvalue ref-qualified function, *this remains an lvalue expression.

在这种情况下,the implicit object parameter*this有什么区别?

In this context, what is the difference between the implicit object parameter and *this?

推荐答案

ref限定符允许基于表达式的引用类型进行函数重载.

ref-qualifiers allow function overloading based on the type of reference of an expression.

由于C ++中没有指向引用的指针(或引用),所以this不能指向(n个右值)引用,因此*this不能是右值.

Since there are no pointers (or references) to references in C++ this can’t point to a (n rvalue) reference, so *this can’t be an rvalue.

rvalue,lvalue和reference(有意)失去了它们的相关性.

rvalue, lvalue and reference (intentionally) loose their relevance once the function is invoked.

这篇关于隐式对象参数和此指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆