隐式对象参数 C++

Implicit object parameter C++

在此link中:隐式对象参数

在这句话中:

If any candidate function is a member function (static or non-static) that does not have an explicit object parameter (since C++23), but not a constructor, it is treated as if it has an extra parameter (implicit object parameter) which represents the object for which they are called and appears before the first of the actual parameters.

我不明白这里为什么要提到static这个词?不是隐式对象参数 ( this ) 指针(其中 ( ( this ) 指针)仅适用于 non-静态函数 ) ?

编辑 在这个 link 中:link

引用:

The keyword this is a rvalue (until C++11)prvalue (since C++11) expression whose value is the address of the implicit object parameter (object on which the non-static member function is being called). It can appear in the following contexts:

考虑一下如果您没有此规则并且有一个静态方法和具有相同(显式)参数的 non-static 方法会发生什么。然后向 non-static 方法添加一个额外的隐式参数 (this),但不向静态方法添加。这将使两种方法的参数列表不同,并允许使用具有相同显式参数的 non-static 方法重载静态方法。

首先,隐式对象参数this指针是有区别的。前者是引用类型,后者是关键字,是指针类型的右值。例如,对于 const 限定的 non-static 成员函数,隐式对象参数的类型为 const X&this 指针的类型为 const X*。而对于 non-const 非静态成员函数,隐式对象参数的类型为 X&this 的类型为 X*。这可以得到证实.


isn't Implicit object parameter the ( this ) pointer ( which ( the ( this ) pointer ) only works with non-static functions )

不,静态和非静态成员函数都有一个 隐式对象参数 用于重载解析,从 over.match.funcs#2 可以看出:

The set of candidate functions can contain both member and non-member functions to be resolved against the same argument list. So that argument and parameter lists are comparable within this heterogeneous set, a member function is considered to have an extra parameter, called the implicit object parameter, which represents the object for which the member function has been called. For the purposes of overload resolution, both static and non-static member functions have an implicit object parameter, but constructors do not.

(强调我的)