Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2004-03-10 12:02:48


David Abrahams wrote:

>"Allen Yao" <yaozhen_at_[hidden]> 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.

Hmm - that didn't work for me. But with the above hint I made the following
compile and function with both VC 7.1 and gcc.

       template <int N>
       void f(int (& a)[N])
                  ^^^^

I had never been able to get demo_fast_binary_archive but could never figure
out the reason - Mystery Solved !

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk