C++ 標準のセクション 9.3.2.1 には、次のように記載されています。
非静的 (9.3) メンバー関数の本体では、キーワード this は、関数が呼び出されるオブジェクトのアドレスを値とする prvalue 式です。クラス X のメンバー関数での this の型は X* です。メンバー関数が const と宣言されている場合、this の型は const X* であり、メンバー関数が volatile と宣言されている場合、this の型は volatile X* であり、メンバー関数が const volatile と宣言されている場合、this の型は const です。揮発性 X*.
this
が prvalue の場合、 の値カテゴリは*this
何ですか? *this
以下は、オブジェクトが右辺値であっても、常に左辺値であることを示唆しています。これは正しいです?可能であれば、標準を参照してください。
struct F;
struct test
{
void operator()(F &&) { std::cout << "rvalue operator()" << std::endl; }
void operator()(F const &&) { std::cout << "const rvalue operator()" << std::endl; }
void operator()(F &) { std::cout << "lvalue operator()" << std::endl; }
void operator()(F const &) { std::cout << "const lvalue operator()" << std::endl; }
};
struct F
{
void operator ()()
{
struct test t;
t(*this);
}
};
int main()
{
struct F f;
f();
std::move(f)();
}
出力:
lvalue operator()
lvalue operator()