如何遍历C ++类的变量成员 [英] How to iterate through variable members of a class C++

查看:1004
本文介绍了如何遍历C ++类的变量成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试对要读取的某些数据对一堆变量进行复杂的变量校正(基于各个相空间的归一化).由于每次校正都遵循相同的过程,所以我想知道是否无论如何,将有迭代地执行此操作,而不是单独处理每个变量(因为我需要大约18-20个变量进行此操作). C ++可以处理吗?有人告诉我要在python中进行尝试,但我觉得可以用C ++进行某种方式...我只是碰壁!

I'm currently trying to do a complicated variable correction to a bunch of variables (based on normalizing in various phase spaces) for some data that I'm reading in. Since each correction follows the same process, I was wondering if there would be anyway to do this iteratively rather than handle each variable by itself (since I need to this for about 18-20 variables). Can C++ handle this? I was told by someone to try this in python but I feel like it could be done in C++ in some way... I'm just hitting a wall!

为您提供一个想法,例如:

To give you an idea, given something like:

class VariableClass{
    public :
      //each object of this class represents an event for this particlular data set 
      //containing the following variables
      double x;
      double y;
      double z;
}

我想做以下事情:

for (int i=0; i < num_variables; i++)
{
   for (int j=0; j < num_events; j++)
   {
     //iterate through events
   }
   //correct variable here, then move on to next one
}

提前感谢您的任何建议!

Thanks in advance for any advice!!!

推荐答案

是的,只需将所有变量放入容器中,例如std::vector.

Yes, just put all your variables into a container, like std::vector, for example.

这篇关于如何遍历C ++类的变量成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆