error: expected unqualified-id before '[' help?

So I'm getting an expected unqualified-id error in the code below. It's a file being called by the main in another file. They are compiled together using g++. Any hints or ideas of what's wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <cstdlib>

using namespace std;


int[] expand_array(int a[], int l, int inc); //error on this line, character 4

int[] expand_array(int a[], int l, int inc)  //error on this line, character 4
{
    int newa[l + inc];
    for(int i = 0; i < l; i++)
    {
        newa[i] = a[i];
    }
    return newa[];
}
Last edited on
maybe you should pass the array by reference and manipulate it inside your function rather than returning an array?

 
bool expand_array( int a[], int 1, int inc, int[] &b );


where b receives whatever array you wanted to return

edit: ya didn't really answer your question did I...
Last edited on
You can't return arrays from functions.

You'll either have to pass the array by reference as ceruleus suggested, or you'll have to put it in a container class (like a vector) or something similar and return that.
Topic archived. No new replies allowed.