We can access private variables of another class when we define copy or move constructors. Does C++ make them friend to each other automatically?
For example:
my_str::my_str(my_str&& m)
{
size_ = m.size_; //accessing private variable another my_str class
buff_ = m.buff_; //accessing private variable another my_str class
m.buff_ = nullptr;
m.size_ = 0;
}
It is not considered friend, but yes, any member function of class
my_strcan access private members of all instances of typemy_str, not just thethisinstance:The general idea behind it is to allow 2 or more objects of the same type to interact without having to expose their private members.