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++, Allegro function library is installed, but no allegro functions are used here.


#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);


Edited 6 Years Ago by sblass92: n/a

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.


This question has already been answered. Start a new discussion instead.