[serialization17] demo_fast_binary_archive.cpp CANNOT compile in gcc 3.3.3

It seems that gcc does not allow this kind of template argument deduction: template <int N> void f(int a[N]) { for (int i = 0; i < N; i++) cout << a[i] << " "; cout << endl; } int main() { int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; f(a); } The error message is: error: no matching function for call to `f(int[10])' I would like to know how to fix this. Is there any workaround? Or if I am missing something?

"Allen Yao" <yaozhen@ustc.edu> writes:
It seems that gcc does not allow this kind of template argument deduction:
template <int N> void f(int a[N]) { for (int i = 0; i < N; i++) cout << a[i] << " "; cout << endl; }
int main() { int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
f(a); }
The error message is:
error: no matching function for call to `f(int[10])'
I would like to know how to fix this. Is there any workaround? Or if I am missing something?
You're missing something. Your declaration of f is equivalent to: template <int N> void f(int* a); try: template <int N> void f(int a(&)[N]) ^^^ instead. -- Dave Abrahams Boost Consulting www.boost-consulting.com

"David Abrahams" <dave@boost-consulting.com> ???? news:un06ox4wu.fsf@boost-consulting.com...
You're missing something. Your declaration of f is equivalent to:
template <int N> void f(int* a);
try:
template <int N> void f(int a(&)[N]) ^^^
It seems that this line should be void f(int (&a)[N]) Thank you very much. BTW: The original demo_fast_binary_archive.cpp seems missing this. May Ramey fix this.
instead.
participants (2)
-
Allen Yao
-
David Abrahams