You can’t copy arrays by value like that.
Here are several solutions, but I recommend #4 for your needs:
-
Use an
std::vector
instead of an array. -
Use a map of pointers to arrays of 3 elements:
int red[3] = {1,0,0}; int green[3] = {0,1,0}; int blue[3] = {0,0,1}; std::map<int,int(*)[3]> colours; colours.insert(std::pair<int,int(*)[3]>(GLUT_LEFT_BUTTON,&red)); colours.insert(std::pair<int,int(*)[3]>(GLUT_MIDDLE_BUTTON,&blue)); colours.insert(std::pair<int,int(*)[3]>(GLUT_RIGHT_BUTTON,&green)); // Watch out for scope here, you may need to create the arrays on the heap.
-
Use boost tuples instead of arrays of 3 elements.
-
Instead of using an array make a new struct that takes 3 elements. Make the
map<int, newstructtype>
. Or wrap your array in a struct as follows:struct Triple { int color[3]; }; // Later in code Triple red = {1, 0, 0}, green = {0, 1, 0}, blue = {0, 0, 1}; std::map<int,Triple> colours; colours.insert(std::pair<int,Triple>(GLUT_LEFT_BUTTON,red)); colours.insert(std::pair<int,Triple>(GLUT_MIDDLE_BUTTON,blue)); colours.insert(std::pair<int,Triple>(GLUT_RIGHT_BUTTON,green));