Why does this reject the listing?

Why is this code not working?

#include <algorithm>
int main() {
  int a[10];
  enum { a_size = sizeof a / sizeof *a };
  std::fill(a, a + a_size, a_size);
}

g ++ 4.1.2 and 4.4.3:

In the function 'int main ()':
Line 5: error: there is no corresponding function to call "fill" (int [10], int *, main () :: <anonymous enum>) '

Is this code valid C ++ 0x?

+3
source share
1 answer

std :: fill is parameterized by the type of the object argument; it does not require an Iterator :: value_type argument. So, as Siliko says, C ++ 03 cannot create a template with a local type.

However, in C ++ 0x, you can use local types to create templates, as they are provided with external communication.

+2
source

Source: https://habr.com/ru/post/1768172/


All Articles