*this
имеет тип ссылки, а не указателя.
The expression ∗this refers to the object for which a member function is invoked.
In a non-static member function, the keyword this is a pointer to the object for which the function
was invoked. In a non-const member function of class X, the type of this is X∗. However, this
is considered an rvalue, so it is not possible to take the address of this or to assign to this. In a
const member function of class X, the type of this is const X∗ to prevent modification of the object
itself
The operand of the built-in indirection operator must be pointer to object or a pointer to function, and the result is the lvalue referring to the pointer or function to which expr points.
refers to разве означает, что тип выражения - ссылка?
refers
означает "относиться" или "ссылаться".struct Foo final
{
int bar = 0;
};
// ...
Foo a;
Foo* p = &a;
(*p).bar = 5;
std::cout << a.bar;
5
- это правильно. Почему будет выведено именно это число? Почему это не означает, что *p
имеет ссылочный тип? Что означает "передача по значению"? Что означает "передача по ссылке"?struct Foo final
{
int a;
Foo() { std::cout << "Foo::Foo()" << std::endl; };
~Foo() { std::cout << "Foo::~Foo()" << std::endl; };
};
// ...
Foo* a = new Foo{};
Foo& b = *a;
Foo& c = *a;
Foo& d = *a;
Foo& e = *a;
Foo& f = *a;
delete a;
"Foo::Foo()"
и "Foo::~Foo()"
? Почему именно столько раз?если х имеет тип указателя на другой тип Т, то разыменование х имеет тип Т, а не Т&&
lvalue reference
буквально означает ссылку на значение.forward declaration
)? Можно ли хранить ссылки на объекты незавершенного типа? Дисклеймер (англ. Disclaimer) — письменный отказ от ответственности.
The lang project is written just for fun, author is not going to take over the world.
T& T::foo() // ссылка
{
return *this;
}
auto T::foo() // T(const T&)
{
return *this; // T&
}
Я действительно считаю С++ неоправданно перегруженным censored