在命名成员函数重载决策过程中,'this'何时会从作用域中消失?

2026-04-16 19:364阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计269个文字,预计阅读时间需要2分钟。

在命名成员函数重载决策过程中,'this'何时会从作用域中消失?

从cppreference出发:调用命名函数...如果表达式E是一个主要表达式,则根据正常函数调用规则(可能涉及ADL)查找其名称。通过此查找找到的函数声明是...

从 cppreference开始:

在命名成员函数重载决策过程中,'this'何时会从作用域中消失?

Call to a named function

<…> If the expression E is a primary expression, the name is looked up following normal rules for function calls (which may involve ADL). The function declarations found by this lookup are (due to the way lookup works) either: <…>

b) all member functions of some class T, in which case, if this is in scope and refers to T, *this is used as the implied object argument. Otherwise (if this is not in scope or does not point to T), a fake object of type T is used as the implied object argument, and if overload resolution subsequently selects a non-static member function, the program is ill-formed.

似乎第二种情况是关于函数内部的func(arg)调用.什么时候不适合这种情况?

或者它不只是在谈论方法中的类似func(arg)的东西吗?

When could this be not in the scope for such cases?

静态成员函数.

本文共计269个文字,预计阅读时间需要2分钟。

在命名成员函数重载决策过程中,'this'何时会从作用域中消失?

从cppreference出发:调用命名函数...如果表达式E是一个主要表达式,则根据正常函数调用规则(可能涉及ADL)查找其名称。通过此查找找到的函数声明是...

从 cppreference开始:

在命名成员函数重载决策过程中,'this'何时会从作用域中消失?

Call to a named function

<…> If the expression E is a primary expression, the name is looked up following normal rules for function calls (which may involve ADL). The function declarations found by this lookup are (due to the way lookup works) either: <…>

b) all member functions of some class T, in which case, if this is in scope and refers to T, *this is used as the implied object argument. Otherwise (if this is not in scope or does not point to T), a fake object of type T is used as the implied object argument, and if overload resolution subsequently selects a non-static member function, the program is ill-formed.

似乎第二种情况是关于函数内部的func(arg)调用.什么时候不适合这种情况?

或者它不只是在谈论方法中的类似func(arg)的东西吗?

When could this be not in the scope for such cases?

静态成员函数.