7

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.

selbie
  • 100,020
  • 15
  • 103
  • 173
uyetch
  • 2,150
  • 3
  • 28
  • 33
  • If it helps, I am willing to post the entire code. Although, I got down voted in a previous question for posting irreverent portion of code. Hence I put only the shorter version here. – uyetch Jan 21 '12 at 10:41
  • 1
    By the way, it would help a lot if you post the actual errors you're getting from the compiler, instead of describing how you understand them. – littleadv Jan 21 '12 at 10:43
  • Here is the error I get after I change vector> to vector > (as suggested in the answers. `In function ‘int main(int, char**)’: error: invalid use of member (did you forget the ‘&’ ?)` – uyetch Jan 21 '12 at 10:47
  • Doesn't help much without letting us know whats on line 110, does it:) – littleadv Jan 21 '12 at 10:48
  • @littleadv Sorry with the line number once again. On 110 its `bvc.push_back(bstemp);` – uyetch Jan 21 '12 at 10:49
  • 3
    `bstemp.count` should be `bstemp.count()` – Mat Jan 21 '12 at 10:49

2 Answers2

15

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.

Mysticial
  • 464,885
  • 45
  • 335
  • 332
  • 3
    the term is called **Maximal munch** if someone is interested for further readings. – max Jan 16 '15 at 03:04
6

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

Yes, pretty nasty syntax issue.

littleadv
  • 20,100
  • 2
  • 36
  • 50