Hey everyone,
Browsed through the forums and a C++ book, but can't find what I'm doing wrong.

1)Goal is to pass colors array to a function that picks a color set from 19 options and modifies red, green, and blue to be used in an allegro function. Each color set can only be picked once.
2) Error occurs when I try and call pickColor() in main, compiler says: expected primary expression before ']' token

Other notes: Array is hard-coded in main (omitted for space reasons) pickColor function doesn't use for loops, so passing array size was unnecessary (actual function contents omitted for space). I'm using Dev-C++ 4.9.9.2, Allegro function library is installed, but no allegro functions are used here.

Thanks!

#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;

void pickColor(int types[][19], int &red, int &green, int &blue) {
}

int main(int argc, char *argv[])
{
    int red = 0, green = 0, blue = 0;
    int colors[4][19];
    
    pickColor(colors[][19], &red, &green, &blue);

system("PAUSE");
return EXIT_SUCCESS;
}

Recommended Answers

All 3 Replies

Are you new to calling functions in C++?

pickColor(colors, red, green, blue);

When you pass an array to a function, you only need to pass the name of the array (i.e starting address) Do not include size declarations

pickColor(color[3][19], red, green, blue); // WRONG!
pickColor(color, red, green, blue); // Correct

Aha! thanks very much, I was under the impression array dimensions beyond two had to be passed, but they only had to be in the function declaration. Same thing with passing variables by reference. Just silly mistakes after a long winter break.

thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.