Hello programmers! I am trying to return an array, made up of 7 members, all type ints via a pointer from a function. Here is a prototype of a function that does this:

int[7] colCountArray={0,0,0,0,0,0,0} //array saved in Board obj.

int* Board::accessColCount()
{
    return &colCountArray;
}

However, my compiler dosnt like this. How can I fix this problem?

int* Board::accessColCount()
{
    return colCountArray;
}

This will return an int-pointer, pointing inside the board objdect, to its colCountArray.

Alternatively

int* Board::accessColCount()
{
    return &colCountArray[0];
}

Simply returning &colCountArray is an int** as the array name itself is a pointer, illustrated by Moschops' reply.

Anyway, this stuff is why C/C++ is difficult for many programmers, dealing with pointer issues and arithmetic.

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.