This is the proto:
message GetIdKeyValueResp {
optional int32 ret = 1;
repeated IpInfo ips = 2;
}
message IpInfo {
optional string ip = 1;
optional string status = 2;
optional uint64 update_time = 3;
optional Disks disks = 4;
}
message DiskHistory {
optional uint64 time = 1;
optional string status = 2;
}
message Disk {
optional uint32 index = 1;
optional string status = 2;
optional uint64 time = 3;
repeated DiskHistory history = 4;
}
message Disks {
optional int32 disk_num = 1;
repeated Disk disk = 2;
}
And when I run the code
GetIdKeyValueResp resp;
for (int i = 0; i < 10; i++) {
IpInfo* ipinfo = resp.add_ips();
cout << &(ipinfo->disks()) << endl;
}
The output is:
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
0x6424880
Obviously they shared an address, so when I modify the disks information of one of the ips, the other ips will also be modified.I want to know why this is and how to solve it.