"error: expected identifier before numeric constant" when trying to define a std::bitset inside a class

1.7k views Asked by At

I'm trying to create a variable of type std::bitset<16> in my class:

#include <bitset>

class foo{
public:
    std::bitset<16> bar (0xfa2);
};

But the program fails to compile with the following error:

$ g++ src/test.h 
src/test.h:5:26: error: expected identifier before numeric constant
    5 |     std::bitset<16> bar (0xfa2);
      |                          ^~~~~
src/test.h:5:26: error: expected ‘,’ or ‘...’ before numeric constant

I don't know what I'm doing wrong. The bitset definition is copied straight from the documentation example so I don't think it should throw any error. I've been trying to fix this for a while, but only noticed that the program compiles if I initialize the bitset without any argument, which is not what I'm trying to do anyways.

0

There are 0 answers