how to put array data into vector?

hey everybody!

i got the code from this site that is supposed to put the bits from an array into a vector, but it does not work and i don't know what i am doing wrong:
1
2
3
4
5
6
7
8
9
10
11
12
   decode_rs();  // recd[] will be error corrected and in polynomial form 

    // put  recd[]s into decoded_lcw[]
    for(i=nn-kk; i < nn; i++)
    {
      decoded_lcw[i - (nn-kk) + index*(nn-kk)] = recd[i];  
    }
  } 
  //put values of decoded_lcw[] into decoded_lcw_vec()
  decoded_lcw_vec( decoded_lcw, decoded_lcw + sizeof(decoded_lcw)/sizeof(decoded_lcw[0]) ) ;
  delete [] decoded_lcw; 
}

the error is:
 
error: no match for call to '(bit_vec {aka std::vector<int>}) (int*&, int*)'

the decoded_lcw_vec vector is typed like this:
 
typedef std::vector<int> bit_vec;


i wanted to use vector<bool> being that i am dealing with bits here but i thought maybe the conversion from int to bool was the problem but obviously i get the same error when the vector is typed int. any help will be much appreciated, thanks in advance.



what is recd and decoded_lcw. Further more: why delete [] decoded_lcw;?

if decoded_lcw is a pointer to a vector you need either derefernce or -> to access the function:
(*decoded_lcw)[i - (nn-kk) + index*(nn-kk)] = recd[i];

what is recd and decoded_lcw. Further more: why delete [] decoded_lcw;?


they are arrays and and you are right about the decoded_lcw, that need not be a pointer.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define mm  6           /* RS code over GF(2**6)  */
#define nn  24          /* nn=2**mm -1   length of codeword */
#define tt  6           /* number of errors that can be corrected */
#define kk  12          /* kk = nn-2*tt  */

  int pp [mm+1] = { 1, 1, 0, 0, 0, 0, 1 } ; /* specify irreducible polynomial coeffts */
  int alpha_to [nn+1], index_of [nn+1], gg [nn-kk+1] ;
  int recd [nn], data [kk], bb [nn-kk] ;


// 1st parameter is 144 bit array from the hamming decode
// 2nd parameter is 72 bit array filled by this decoder 
void
ldu1::decode_reed_solomon(uint16_t* rs_codeword)
{
  generate_gf(  ) ;
  gen_poly(  ) ;
  
  int decoded_lcw[72] = {0} ;
  int i;
  int parity[72] = {0};    //  72-bit array for parity bits
  int payload[72] = {0};  //  72-bit array for data bits 
  for (i=72; i<144; i++) parity[i-72] = rs_codeword[i] ; //  split 72 parity bits from rs_codewords
  for (i=0; i<72; i++) payload[i] = rs_codeword[i] ;    //  split 72 data bits from rs_codewords

  for(int index = 0; index < 6; index++)// form and decode 6 24-bit codewords 
  {                                                        
    int i;                                                               // putting the bits in rec[nn]
    for (i=0; i<nn-kk; i++)  recd[i] = bb[ i + (index*(nn-kk)) ] ;      // the 12 parity hex-bits first
    for (i=0; i<kk; i++) recd[i+nn-kk] = data[ i + (index*(nn-kk)) ] ; // the 12 data hex-bits second
    //  put 24-bit codeword into index form; 
    for (i=0; i<nn; i++)                  
       recd[i] = index_of[recd[i]] ;         
                                          
    decode_rs();  // recd[] will be error corrected and in polynomial form 

    // put six 12-bit recd[]s into decoded_lcw[]
    for(i=nn-kk; i < nn; i++)
    {
      decoded_lcw[i - (nn-kk) + index*(nn-kk)] = recd[i];  
    }
  } 
  printf("decoded lcw:\n");
      for(i=0;i<72;i++)
      printf("%d",decoded_lcw[i]);
      printf("\n"); 

  decoded_lcw_vec(decoded_lcw, decoded_lcw + sizeof decoded_lcw / sizeof decoded_lcw[0]) ; 
	for(int i = 0 ; i < 72; i++ ) 
		cout<< "\n Vector = " << decoded_lcw_vec[i] ;
}


but the error remains:
 
error: no match for call to '(bit_vec {aka std::vector<int>}) (int [72], int*)'

Thanks!!
Last edited on
does anybody have anything for this error? i have found nothing all day.
I don't even see you using bit_vec anywhere?

Is it in the decoded_lcw_vec function?

also it looks ike you are tyring to us an int array and a constructor parameter for the vector.

like:

1
2
3
4
int array[72];

std::vector<int> vec
vec(array);


AFAIK that doesn't work. You have to add each element 1 at a time.

*without constructor I mean.
Last edited on

I don't even see you using bit_vec anywhere?

bit vec is a type def. in the header file:
1
2
3
4
5
6
7
8
typedef std::vector<int> bit_vec;
typedef const std::vector<int> const_bit_vec;

   //Return a reference to the decoded link control word
   const_bit_vec& decoded_lcw() const;
  
   //bit vector to store the decoded link control word
   bit_vec decoded_lcw_vec;



i am trying to fill the vector (on line 48 above) with the contents of the array decoded_lcw like this:
 
decoded_lcw_vec(decoded_lcw, decoded_lcw + sizeof decoded_lcw / sizeof decoded_lcw[0]) ;

the error i get is:

error: no match for call to '(bit_vec {aka std::vector<int>}) (int [72], int*)'


BTW i got the code that i used above from here: http://www.cplusplus.com/forum/general/62900/
looks like it worked for them? what am i doing wrong?
Thanks!
Last edited on
Do you have operator() overloaded for the vector? Or are you trying to call constructor(copy). Basically what I think you want is

bit_vec decoded_lcw_vec(decoded_lcw, decoded_lcw + sizeof decoded_lcw / sizeof decoded_lcw[0]) ; to call the copy constructor instead of trying to call the default constructor then operator().

Ps you could simply put 72 instead of the sizeof since it doesn't look dynamic at all. http://ideone.com/IFIAkH

BTW i got the code that i used above from here: http://www.cplusplus.com/forum/general/62900/
looks like it worked for them? what am i doing wrong?
Thanks!
They are using the constructor:
http://www.cplusplus.com/reference/vector/vector/vector/

You are using operator()
Last edited on
oh nice the error is gone from the compile! THANKS A BUNCH!
Topic archived. No new replies allowed.