In C++, how do I check the allocated value/size a struct array has been initialized to?
int main()
{
struct A
{
int x;
int y;
};
A* a = new A[20];
}
sizeof(a) / sizeof(a[0]);
returns a value of 1. So this is not what I was expecting.
Is there any way I can do this so that I can get the size (20) allocated for a
?
Where I am going to use it is in a case like this:
void fillArray(A valueToFill, int matrixSize, A *a)
{
for (int i = 0; i < matrixSize; i++)
{
a[i] = valueToFill;
}
}
I intend to check if size of a
is actually matrixSize
. Otherwise it will crash if matrixSize
is bigger than a
.