C4047 '>' const int differs in level of indirection from int

I do not understand what this error message means.

What is wrong with this code?

1
2
3
4
5
6
7
8
9
10
11
12
int getMax(const int* pArray, size_t len)
{
	const int * pArrayEnd = pArray + len;
	int max = 0;
	while (pArray < pArrayEnd)
	{
		if (*pArray > max)
			max = *pArray;
		pArray++;
	}
	return max;
}
Dunno. Worked OK for me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

int getMax(const int* pArray, size_t len)
{
        const int * pArrayEnd = pArray + len;
        int max = 0;
        while (pArray < pArrayEnd)
        {
                if (*pArray > max)
                        max = *pArray;
                pArray++;
        }
        return max;
}


int main()
{
   int A[] = { 1, 6, -2, 3 };
   cout << getMax( A, 4 );
}

Last edited on
@shoo11,
C4047 is a warning about levels of indirection, potential type mismatch, it is not an error.

The ā€˜Cā€™ denotes compiler.

See: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4047?view=vs-2019#example
Last edited on
Topic archived. No new replies allowed.