>>108708592
that is not entirely true. it is actually a different type than an lvalue reference, but behaves identically.
#include <iostream>
int main()
{
int a = 10;
int &&r = 10;
int &l = a;
if constexpr (!std::is_same_v<decltype(r), decltype(l)>)
std::cout << "not the same\n";
}
>>108709022
its so u can do something like this. as you may see i am making a deep copy of the data. in c when u do '=' on a struct the struct itself is copied, and does not allow reallocation or any other desired outcome.
#include <cstring>
#include <iostream>
class C
{
private:
int *mem_ = nullptr;
int size_ = 0;
public:
C(int size) : size_(size)
{
mem_ = new int[size];
}
C() = default;
~C()
{
if (mem_)
delete[] mem_;
}
C &operator=(const C &other)
{
if (this == &other)
return *this;
if (mem_)
delete[] mem_;
size_ = other.size_;
mem_ = new int[size_];
std::memcpy(mem_, other.mem_, size_ * sizeof(int));
return *this;
}
void fill()
{
for (int i = 0; i < size_; i++)
mem_[i] = i;
}
void print()
{
std::cout << mem_ << "\n";
for (int i = 0; i < size_; i++)
std::cout << mem_[i] << " ";
std::cout << "\n";
}
};
int main()
{
C c1(10);
C c2;
c1.fill();
c2 = c1;
c1.print();
c2.print();
}