variable loop
-
i have many many member variables named m_1 , m_2 , m_3 , m_4 ,.... and i want to access them using a for loop by an index (i) like that : for (int i=1; i
Two solutions: 1. Don't use member variables like that. Use an array: m_whatever[100], then it's easy to loop through it:
for (int i = 0; m_whatever[i] = 0; ...)
2. If you must do it with individual variables, you can use a macro, like this:
#define M_(i) m_##i
for (int i = 1; M_(i) = 0; ...)
Regards, Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
-
i have many many member variables named m_1 , m_2 , m_3 , m_4 ,.... and i want to access them using a for loop by an index (i) like that : for (int i=1; i
Assuming the series are all of the same type, you can make an array of pointers and walk that array. Take care to not fall off the end of the array.