Roger Pate
Roger Pate

Reputation:

Why does this reject an enum?

Why does this code fail?

#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 function 'int main()':
Line 5: error: no matching function for call to 'fill(int [10], int*, main()::<anonymous enum>)'

Is this code valid C++0x?

Upvotes: 3

Views: 276

Answers (1)

Potatoswatter
Potatoswatter

Reputation: 137800

std::fill is parameterized on the type of its object argument; it does not require an argument of Iterator::value_type. So, as In silico says, C++03 can't instantiate the template with a local type.

However, in C++0x, you can use local types to instantiate templates, because they are given external linkage.

Upvotes: 2

Related Questions