Reputation: 2488
I'm collecting a set of colors in separate arrays. After then i want to store all of them in an array that contains these arrays, so i can iterate through all colors at once. i want to do it like this:
const float COLOR_GREEN[3] = {0.00f, 1.00f, 0.01f};
const float COLOR_LIGHT_PURPLE[3] = {0.99f, 0.00f, 0.99f};
const float COLOR_CYAN[3] = {0.00f, 1.00f, 0.99f};
const float COLOR_BLUE[3] = {0.00f, 0.00f, 0.99f};
const float COLOR_YELLOW[3] = {1.00f, 1.00f, 0.01f};
const float COLOR_BROWN[3] = {0.82f, 0.40f, 0.12f};
const float COLOR_ORANGE[3] = {1.00f, 0.55f, 0.001f};
const float COLOR_PINK[3] = {1.00f, 0.20f, 0.701f};
const float COLOR_LIGHT_GREY[3] = {0.67f, 0.67f, 0.671f};
const float COLOR_DARK_GREY[3] = {0.33f, 0.33f, 0.333f};
const float COLOR_DARK_GREEN[3] = {0.18f, 0.54f, 0.341f};
const float COLOR_DARK_RED[3] = {0.20f, 0.00f, 0.01f};
const float COLOR_DARK_PURPLE[3] = {0.50f, 0.00f, 0.51f};
const float COLOR_DIRTY_GOLD[3] = {0.50f, 0.51f, 0.00f};
const float COLOR_BLUEISH_GREEN[3] = {0.00f, 0.50f, 0.51f};
static const float COLOR_LIST[15][3] = {{COLOR_GREEN},
{COLOR_LIGHT_PURPLE},
{COLOR_CYAN},
{COLOR_BLUE},
{COLOR_YELLOW},
{COLOR_BROWN},
{COLOR_ORANGE},
{COLOR_PINK},
{COLOR_LIGHT_GREY},
{COLOR_DARK_GREY},
{COLOR_DARK_GREEN},
{COLOR_DARK_RED},
{COLOR_DARK_PURPLE},
{COLOR_DIRTY_GOLD},
{COLOR_BLUEISH_GREEN}
};
};
But it's not possible like this because i can't convert const float* to const float. at the end i want to iterate through this array like this:
for(int i = 0; i < 15; ++i)
{
std::cout << COLOR_LIST[i][0] << ", " << COLOR_LIST[i][1] << "," << COLOR_LIST[i][2] << std::endl;
}
where COLOR_LIST[0][0] = 0.00f, COLOR_LIST[0][1] = 1.00f, COLOR_LIST[0][2] = 0.01f, etc...
what am i doing wrong here? thanks
Upvotes: 0
Views: 348
Reputation: 4126
Make it to point to array..
static const float* COLOR_LIST[15] = {COLOR_GREEN,
COLOR_LIGHT_PURPLE,
COLOR_CYAN,
COLOR_BLUE,
COLOR_YELLOW,
COLOR_BROWN,
COLOR_ORANGE,
COLOR_PINK,
COLOR_LIGHT_GREY,
COLOR_DARK_GREY,
COLOR_DARK_GREEN,
COLOR_DARK_RED,
COLOR_DARK_PURPLE,
COLOR_DIRTY_GOLD,
COLOR_BLUEISH_GREEN
};
Upvotes: 1