uyetch
uyetch

Reputation: 2190

Is it possible to create a vector of bitsets?

I am trying to create a vector of bitsets in C++. For this, I have tried the attempt as shown in the code snippet below:

vector<bitset<8>> bvc;
    while (true) {
        bitset<8> bstemp( (long) xtemp );
        if (bstemp.count == y1) {
            bvc.push_back(bstemp);
        }
        if ( xtemp == 0) {
            break;
        }
        xtemp = (xtemp-1) & ntemp;
    }

When I try to compile the program, I get the error that reads that bvc was not declared in the scope. It further tells that the template argument 1 and 2 are invalid. (the 1st line). Also, in the line containing bvc.push_back(bstemp), I am getting an error that reads invalid use of member function.

Upvotes: 8

Views: 13880

Answers (2)

Mysticial
Mysticial

Reputation: 471249

I have a feeling that you're using pre C++11.

Change this:

vector<bitset<8>> bvc;

to this:

vector<bitset<8> > bvc;

Otherwise, the >> is parsed as the right-shift operator. This was "fixed" in C++11.

Upvotes: 16

littleadv
littleadv

Reputation: 20272

Change vector<bitset<8>> bvc to vector<bitset<8> > bvc. Note the space. >> is an operator.

Yes, pretty nasty syntax issue.

Upvotes: 7

Related Questions