开发者

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 'fil开发者_C百科l(int [10], int*, main()::<anonymous enum>)'

Is this code valid C++0x?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜