0

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?

3
Contributors
4
Replies
19
Views
4 Years
Discussion Span
Last Post by rubberman
0
int* Board::accessColCount()
{
    return colCountArray;
}

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

Edited by Moschops

0

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.

0

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

Edited by rubberman

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.