Question

I have some data that comes in as a 32 bit word which represents 32 channels either firing or not firing. I then want to get this data and individually add the channels up as an int so I can find out out many times that channel has fired.

e.g for 4 channels:

001001 001000

Would become:

002001

So far I keep getting this type of error:

error: no match for ‘operator=’ in ‘*(((std::vector<unsigned int, std::allocator<unsigned int> >*)(((long unsigned int)i) * 24ul)) + dat) = data2[i]’

Any ideas on how to help me? Thanks =)

void binary(int convert,vector <unsigned>* dat) {
    bitset<32> bits(convert);
    //cout << bits.to_string() << endl;
    //cout << bits.to_ulong() << endl;
    char data[32];
    int data2[32];

    for(unsigned i = 0; i < 32; ++i) {
      data[i] = bits[i];
      data2[i] = data[i];
      dat[i] = data2[i]; ///ERROR WAS HERE
    }

    for(unsigned i = 32; i; --i) {
      int j;
      cout << (data2[i-1]);
      }
    cout << endl;
  }


  void SerDi() {
    vector <unsigned> dat(32);

    cout << "    Reading data from memory..." << endl;
    ValVector< uint32_t> data=hw.getNode("SerDi.RAM").readBlock(8);

    hw.dispatch();
    cout << data[0]<<endl;
    cout << data[1]<<endl;
    for (unsigned i = 2; i < 7; i++) {
      binary(data[i], &dat);
    }
    //graph(dat);
  }
Was it helpful?

Solution

I'm guessing this is the line that contains the problem:

dat[i] = data2[i];

It's because dat is a pointer, so dat[i] is indexing dat as a normal array and not a vector object. To solve it, don't pass it as a pointer, pass it by reference instead:

void binary(int convert,vector <unsigned>& dat) { ... }

and call it without the address-of operator:

binary(data[i], dat);

Or keep the code as it is now, but change the line in question to dereference the pointer instead:

(*dat)[i] = data2[i];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top