Search code examples
c++vector

E0137 expression must be a modifiable L-value


Im writing a small change to a code in visual studio and Im getting this error:

Error (active) E0137 expression must be a modifiable L-value
C:\Users\...\events.cpp 75

This is the piece of code I added: (In bold is the line I'm getting the error):

void EV_HLDM_MuzzleFlash(vec3_t pos, float amount)
{
    dlight_t *dl = gEngfuncs.pEfxAPI->CL_AllocDlight(0);
    dl->origin = pos;  // ERROR HERE
    dl->color.r = 255; // red
    dl->color.g = 255; // green
    dl->color.b = 128; // blue
    dl->radius = amount * 100;
    dl->die = gEngfuncs.GetClientTime() + 0.01;
}

And here is the definition of dlight:

typedef float vec3_t[3]; 

typedef struct dlight_s
{
    vec3_t  origin;
    float   radius;
    color24 color;
    float   die;                // stop lighting after this time
    float   decay;              // drop this each second
    float   minlight;           // don't add when contributing less
    int     key;
    qboolean    dark;           // subtracts light instead of adding
} dlight_t;

I don't really understand what´s wrong. I'm defining origin as a vector for the struct dlight and then I'm giving a vector in EV_HLDM_MuzzleFlash. I don't understand what the problem is. Please help.

I tried changing the first line in dlight_t to Vector and the previous error dissapear, but I got new errors:

Error C3646 'origin': unknown override specifier 
Error C4430 Missing type specifier; int is assumed Note: C++ does not support default-int 

I get 46 times those 2 errors when changing from vec3_t to Vector.

What am I missing?


Solution

  • The origin field is defined as an array, and arrays can't be assigned to directly. You'll need to use memcpy to copy the array elements.

    memcpy(dl->origin, pos, sizeof dl->origin);