I usually work in an environment where the highest supported version of modern C++ is C++14. I was experimenting with std::size
from <iterator>
in c++17 and came across the following issue / problem / lack of understanding on my part.
In the following code snippet the use of of size(a)
in main
works correctly but the usage in print
refuses to compile stating that no matching function for call to 'size(int*&)'
exists.
I know there are other, better ways of doing this but I would like to know why it works in the one context and not the other.
For what its worth I used the following online compiler and simply turned the -std=c++17
flag on.
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
void print(int a[])
{
for(int i = 0; i < size(a); i++)
cout << a[i] << endl;
}
int main()
{
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
cout << "Directly" << endl;
for(int i = 0; i < size(a); i++)
cout << a[i] << endl;
cout << "Via function" << endl;
print(a);
return 0;
}