在C++中一个对象可以访问另一个同类对象的私有成员吗?

本人是初学者,在研究类的拷贝构造函数时遇到了一个问题,既然一个对象能把另一个对象的全部信息给拷贝过来,那么是否可以拷贝它的私有成员呢,测试了一下,用对象B拷贝构造一个对象A出来,代码没有报错,正常运行,而且输出对象A的信息也和B的信息完全一样。然后就想既然拷贝构造可以访问另一个对象的私有成员,那么可不可以通过对象A去修改对象B呢?结果也是可行的,我去查了一下网上的相关信息,得到的结论大部分都是私有成员只能被本对象访问,而不能被同类的其他对象访问。但是测试结果却是成功的,可如果是这样的和话,那么为什么还需要一个静态成员呢(静态成员可以被同类中所有的对象访问,那一个对象的非静态私有成员都可以被其他对象访问了,再需要一个静态成员不是多此一举吗?),下面是相关的测试代码,经本人测试可以运行:

#include <iostream>
using namespace std;
//构造函数调用规则
//编译器默认提供无参构造函数(空实现)、析构函数(空实现)、拷贝构造函数(值拷贝)
//等级:无参 < 有参 < 拷贝
//顺序:编译器只会提供比 用户自定义构造函数 等级高的构造函数

class Object {
public:
    Object() {
        cout << "默认无参构造" << endl;
    }
    Object(int id,string name) {
        cout << "默认有参构造" << endl;
        m_id = id;
        m_name = name;
    }
    ~Object() {
        cout << "析构" << endl;
    }
    Object(Object& o) {
        cout << "默认拷贝构造" << endl;
        m_id = o.m_id;
        m_name = o.m_name;
    }
    void test() {
        cout << "id:" << m_id << endl;
        cout << "name:" << m_name << endl;
    }
    void test1(Object& o) {
        o.m_id = 20;
        o.m_name = "李四";
    }
    int m_id;
private:
    string m_name;
};
int main() {
    Object B(10,"张三");
    Object A = B;
    A.test();
    A.test1(B);
    B.test();
}

成功运行,下面是运行结果:

默认有参构造
默认拷贝构造
id:10
name:张三
id:20
name:李四
析构
析构

如果有误,还请各位指出

public/procted/private不是按对象来限制访问的,它们只是限制成员函数/数据的可见性,以便编译器在编译时进行检查。比如private表示一个成员函数/数据只在这个类的所有成员函数可见,而不管访问这个私有成员是这个对象本身,还是这个类的另一个对象。

FROM https://en.cppreference.com/w/cpp/language/access#Private_member_access

The name of every class member (static, non-static, function, type, etc) has an associated "member access". When a name of the member is used anywhere a program, its access is checked, and if it does not satisfy the access rules, the program does not compile

Private member access

Private members form the implementation of a class, as well as the private interface for the other members of the class.

A private member of a class is only accessible to the members and friends of that class, regardless of whether the members are on the same or different instances

不可以,但是可以通过构造函数,或者方法传参。