TITLE: STL bitset versus vector (Newsgroups: comp.lang.c++, 7 Oct 99) BRIODY: John Briody > I have a couple of questions related to the STL bitset class. > 1 I do not know the size of my bitset at compile time. How do I > create a bitset class member object at runtime when the correct size > becomes available. From my admittedly limited understanding of STL the > size of the bitset is supplied in the declaration ie > > bitset m_bsPresent; KUEHL: Dietmar Kuehl std::vector flags(no_flags); Unless you can accept a maximum number of bits to be maintained by the bit set, you cannot use the class 'bitset'. The major difference between 'bitset' and 'vector' is that 'bitset' can avoid storing the size of the bit set (and its current capacity) and thus everything can be done static with even the pointer to the representation saved. For 'vector' it is necessary to allocate the representation on the heap because you cannot tell how many memory would be necessary. In addition to the resulting pointer, 'vector' has to store the size and the current capacity (both are normally stored as pointers). You have to decide what you want: The low overhead of 'bitset' or the flexibility of 'vector'. There one approach which is not covered by the standard library: A number of elements specified at construction time with no way to resize the resulting vector. This would save one pointer compared to 'vector'. BRIODY: > 2 I would also like to use the STL vector class to declare an > array of such bitsets. However, I am struggling with the syntax. > Any help would be appreciated. KUEHL: Where is the problem: std::vector > bitset_array(17); Of course, you should note that there is a space between the two '>' signs: Otherwise, this would be a token, namely the token for right shift. Thus, a space is required there to separate the tokens.