passing variable to 'for' loop

can you only pass pointers, or is it the way im declaring the variable is incorrect?
closed account (z05DSL3A)
I don't understand what you are asking. Can you explain some more or post some code?
Last edited on
float a;
float *p_a = &a;

for (int b = 0; b < 5;b++){
*p_a = b;
}


ok this is all nested in a function that is a member of a class, the variable is declared within the function, and when trying to use it in a for loop (also in the same function), it gave me an error. So, I had to use a pointer.

I was wondering, whether this had to do with the function being a member of a class or do you always need pointers when dealing with for loops.
Last edited on
closed account (z05DSL3A)
Do you know what the error was?

There should be no problem with code such as
1
2
3
4
5
6
7
8
9
10
11
12
13
class Foo
{
    void Bar()
    {
        float x;
        for(int i =0; i< 5; i++)
        {
            x = i; // Warning C4244: '=' : conversion from 'int' to 'float', 
                     // possible loss of data

       }
    }
};
wierd, it works fine now, must have been something I did before.

thank you.
Topic archived. No new replies allowed.