-2

I have this program I'm working on, and one part of it is a linked list which I am working on making. I got this far, but at this point in the code it tells me (on the 3rd to last line) that inst must be a modifiable lvalue. I'm not sure what I'm doing wrong here.

#include <iostream>

using namespace std;

struct node{
    float color[3];
    float v[2*3];
    node *next;
};

class TriangleList {
    private: node *head;
    private: node * tail;

public: 
    TriangleList() {
        head = NULL;
        tail = NULL;
    }

    void add(float vertices[], float colors[]) {
        node *inst = new node;
        inst->v = vertices;
    }
};
PCRevolt
  • 129
  • 1
  • 1
  • 8

1 Answers1

0

Below statement is not correct, as you can't do inst->v = vertices because by doing this you are trying to change the base address of v, read the error properly.

error: incompatible types in assignment of ‘float’ to ‘float [6]’*

inst->v = vertices;

you may want to do like below

for(int i=0;i<len;i++) { /* len is the length of vertices */
       inst->v[i] = vertices[i];
}
Achal
  • 11,821
  • 2
  • 15
  • 37