copying data in arrays

I have to copy data from locations of one array in to another array,
for that i am calling function below, there are errors
1
2
3
4
5
6
7
8
9
10
11
12
13
template <std::size_t size_source , std::size_t size_dest>
void cpy_data(std::array<unsigned int, size_source>& source_location, std::array<unsigned int, size_dest>& dest_location, int no_mem_locations)                  //! copy from ll_hci payload to hci_host payload
 {
    int i;
    for(i=0;i<no_mem_locations;i++)
    {
       dest_location[i] = source_location[i];
    }
 }

// function call
cpy_data(key_arr[8], M0[16], 8);


Errors:no matching function for call to ‘cpy_data(unsigned int&, unsigned int&, unsigned int)’
cpy_data(key_arr[8], M0[16], 8);
are key_arr and MO also std::array<> ?

if so you should pass them by : cpy_data( key_arr, MO, 8 ) ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <algorithm>
#include <array>

template <std::size_t size_source , std::size_t size_dest>
  void cpy_data( std::array<std::size_t, size_source>& source_location,
                 std::array<std::size_t, size_dest>& dest_location
                 // int no_mem_locations
                 ) //! copy from ll_hci payload to hci_host payload
 {
    std::copy( source_location.begin(), source_location.end(),
               dest_location.begin() );
 }

int main()
{
    std::array<std::size_t, 5> arr = { 99, 120, 34, 42, 56 };
    std::array<std::size_t, 10> arr2 = { { 0 } };
    
    std::cout << "Arr2: ";
    for( auto& i : arr2 ) std::cout << i << " ";
    
    std::cout << std::endl;
    
    cpy_data( arr, arr2 ); // <==== !!

    std::cout << "Arr2: ";
    for( auto& i : arr2 ) std::cout << i << " ";
}

Arr2: 0 0 0 0 0 0 0 0 0 0 
Arr2: 99 120 34 42 56 0 0 0 0 0
Last edited on
thanks
Topic archived. No new replies allowed.