error C2440: '=' : cannot convert from 'float *' to 'float'

I am trying to retreive a floating point value from an array. I am still a bit rusty with pointers so I'm not sure how to fix this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void Lightwave::GetColourList(float *colour_array)
{
    float *red, *green, *blue, *alpha;
    int position = 0;

    for(unsigned int poly=0; poly < total_polygons; poly++)
    {
         for(unsigned int vertex=0; vertex<3; vertex++)
	 {
                 red = ReturnRedColour(poly);
		 green = ReturnGreenColour(poly);
		 blue = ReturnBlueColour(poly);
		 alpha = ReturnAlphaColour(poly);

                 colour_array[position]	= red;           // ERROR
                 colour_array[position + 1] = green;    // ERROR
                 colour_array[position + 2] = blue;      // ERROR
                 colour_array[position + 3] = alpha;    // ERROR
                 
                 position += 4;
	}
    }
}

1
2
3
4
5
6
// Here is one of the ReturnColour Methods
float *Lightwave::ReturnRedColour(unsigned int current_polygon)
{
    int current_surface = polygons[current_polygon].surface;
    return &surfaces[ current_surface - 1 ].colour.red;
}


Sorry for the poor formatting. New to this board and don't know how to change it. Any help with this problem would be greatly appreciated. Thanks.
Last edited on
There's a set of Format icons to the right of your post that format your code.

I don't think you need pointers here, besides the parameter colour_array. I assume it's an array large enough for your purposes.

Remving pointers, and assuming that the colors are floats:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void Lightwave::GetColourList(float *colour_array)
{
    float red, green, blue, alpha;
    int position = 0;

    for(unsigned int poly=0; poly < total_polygons; poly++)
    {
        for(unsigned int vertex=0; vertex<3; vertex++)
        {
            red = ReturnRedColour(poly);
            green = ReturnGreenColour(poly);
            blue = ReturnBlueColour(poly);
            alpha = ReturnAlphaColour(poly);

            colour_array[position] = red;
            colour_array[position + 1] = green;
            colour_array[position + 2] = blue;
            colour_array[position + 3] = alpha;

            position += 4;
        }
    }
}

float Lightwave::ReturnColour(unsigned int current_polygon)
{
    int current_surface = polygons[current_polygon].surface;
    return surfaces[ current_surface - 1 ].colour.red;
}
Hi. Ok. I will give it a try. Thanks.
Or you should add * to all pointer when you read it's value

1
2
3
4
                 colour_array[position]	= *red;           // ERROR
                 colour_array[position + 1] = *green;    // ERROR
                 colour_array[position + 2] = *blue;      // ERROR
                 colour_array[position + 3] = *alpha;  // ERROR 

Last edited on
Hi. Nice idea. I am sure I tried that (probably didn't) but I will give it a go later and report on what happens. Thanks.
I used the second method and it works well. Thanks for the help.
Topic archived. No new replies allowed.