Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

incompatible types in assignment of ‘float’ to ‘float [16]’

I have struct:

struct mat4 {
    float m[16];
    mat4();
    ...
    float *getFloat();
}

float *mat4::getFloat() {
    return m;
}

Now I want to make m equal to m from newly created matrix r:

void mat4::rotate(vec3 v) {
    mat4 r, rx, ry, rz;
    ...
    matrix calculations
    ...
    m = *r.getFloat();
}

But this gives me error "incompatible types in assignment of ‘float’ to ‘float [16]’" I have searched Google and tried different ways but no success so far. Please tell me how could I do that?

like image 429
Karmo Rosental Avatar asked Oct 28 '25 12:10

Karmo Rosental


1 Answers

getFloat() returns a pointer. m is an array. If you want to copy all of what is returned into m you will need to use std::copy or std::memcpy:

std::memcpy(m, r.getFloat(), sizeof(m));

If you meant to get just one float from getFloat() you could do:

  • m[0] = *r.getFloat();
like image 136
Flexo Avatar answered Oct 30 '25 01:10

Flexo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!