修改C+的本征成员的问题+;结构 我有以下C++结构< /P> struct voxel { const std::vector<Eigen::ArrayXf>& getVoltage() const { return m_voltage; } const std::vector<int>& getChannelIndex() const { return m_channelIndex; } float getx() { return m_x; } float gety() { return m_y; } float getz() { return m_z; } void appendVoltage(Eigen::ArrayXf v) { m_voltage.push_back(v); } void appendChannelIndex(int c) { m_channelIndex.push_back(c); } void setPosition(float x, float y, float z) { m_x = x; m_y = y; m_z = z; } void change(int c) { m_voltage.at(c)(0) = -100; std::cout << m_voltage.at(c) << "\n"; } private: std::vector<Eigen::ArrayXf> m_voltage; std::vector<int> m_channelIndex; float m_x; float m_y; float m_z; };

修改C+的本征成员的问题+;结构 我有以下C++结构< /P> struct voxel { const std::vector<Eigen::ArrayXf>& getVoltage() const { return m_voltage; } const std::vector<int>& getChannelIndex() const { return m_channelIndex; } float getx() { return m_x; } float gety() { return m_y; } float getz() { return m_z; } void appendVoltage(Eigen::ArrayXf v) { m_voltage.push_back(v); } void appendChannelIndex(int c) { m_channelIndex.push_back(c); } void setPosition(float x, float y, float z) { m_x = x; m_y = y; m_z = z; } void change(int c) { m_voltage.at(c)(0) = -100; std::cout << m_voltage.at(c) << "\n"; } private: std::vector<Eigen::ArrayXf> m_voltage; std::vector<int> m_channelIndex; float m_x; float m_y; float m_z; };,c++,class,struct,pass-by-reference,eigen,C++,Class,Struct,Pass By Reference,Eigen,我尝试更改体素的第一个数组 vxbuffer.getVoxel(0).change(0); std::cout << vxbuffer.getVoltage2(0).at(0) << "\n"; vxbuffer.getVoxel(0).change(0); std::coutvxbuffer。getVoxel(0)未返回对容器中体素的引用。您正在返回它的副本,因为体素getVoxel(ssize\u t voxelId)的返回类型是体素,而不是体素& 然后在类型为体

我尝试更改
体素的第一个数组

vxbuffer.getVoxel(0).change(0); 
std::cout << vxbuffer.getVoltage2(0).at(0) << "\n";
vxbuffer.getVoxel(0).change(0);
std::cout
vxbuffer。getVoxel(0)
未返回对容器中
体素的引用。您正在返回它的副本,因为
体素getVoxel(ssize\u t voxelId)
的返回类型是
体素
,而不是
体素&

然后在类型为
体素
的临时对象上调用
.change(0)
,而不是在容器中的
体素
对象上调用

voxel vx1;
vx1.setPosition(1.1, 2.1, 3.1);
vx1.appendChannelIndex(1);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(10, 0.0, 10 - 1.0));
vx1.appendChannelIndex(2);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(20, 0.0, 20 - 1.0));
vx1.appendChannelIndex(3);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(30, 0.0, 30 - 1.0));

voxelBuffer vxbuffer;
vxbuffer.voxels.push_back(vx1);
vxbuffer.getVoxel(0).change(0); 
std::cout << vxbuffer.getVoltage2(0).at(0) << "\n";