How to fix ‘No match for operator[]’ error (c++)

Firstly, you use both ar and arr, while arr is an array and ar is a list. This is both confusing to the reader and (it turns out) to the code author.

In C++, std::list doesn’t have random access. You cannot use ar[], since operator[] is not defined for lists. Further, largestOfArray expects an array, not a list. You probably intended to use arr there instead of ar.

Leave a Comment