New to STL. Want to create a vector of bitsets (or any templated class)
From: as mellow as a horse (mail_at_MICKmoss42.fslife.co.uk)
Date: 06/25/04
- Next message: Rufus V. Smith: "Re: Does length of function/variable names matter?"
- Previous message: Marlene Stebbins: "Re: [C] determining size of an array in a function"
- Next in thread: Francis Glassborow: "Re: New to STL. Want to create a vector of bitsets (or any templated class)"
- Reply: Francis Glassborow: "Re: New to STL. Want to create a vector of bitsets (or any templated class)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Jun 2004 14:51:02 +0100
If you want you can skip this bumph and go down to the summary.
I'm new to stl like I say, but I know how to create a vector of built-in
data-types or my own classes (only non-templated ones, more later). I'm
still very hazy on iterators, but that can wait a bit.
I've just discovered the bitset container and realised it would provide a
good solution to a program I wrote a few years ago where I created long
bit-strings (typically 80 bits) using char arrays. Because bitsets are
fixed in length, and because those bitstrings I mentioned were logically
divided into smaller segments (not necessarily all of equal length) I would
want an array of these. That's easily done, but I recall I would also have
liked the bitstring to be of a non-fixed length either by extending the size
of a segment or inserting/appending another segment (or both).
So that's where vector comes in. Given a total bitstring length of 80
divided into segments such as (for example) 10, 15, 6, 13, 16, 8, 12 (should
total 80), I would like to do something like
// vector container (v) of size 7 already created (but how exactly?)
v[0] = new bitset<10> (500,000); // ideally a random number between 0 and
2^10, but good enough here
v[1] = new bitset<15> (2000000); // ditto for 2^15
etc.
SUMMARY:
But I've just realised I can't even work out how to create a vector
containing objects of any templated class (including my own), let alone an
stl container!
e.g.
vector<int> x[10]; // works fine
vector<CMyObject<int>> x[10]; // can't work out syntax for this!
vector<bitset<10>> x[7]; // ditto, and not what I want even if not!
If you've read the full message, you'll see the particular problem with the
latter example is that even if it did work, I would be stuck with a
container of bitsets all of the same size which I don't want.
- Next message: Rufus V. Smith: "Re: Does length of function/variable names matter?"
- Previous message: Marlene Stebbins: "Re: [C] determining size of an array in a function"
- Next in thread: Francis Glassborow: "Re: New to STL. Want to create a vector of bitsets (or any templated class)"
- Reply: Francis Glassborow: "Re: New to STL. Want to create a vector of bitsets (or any templated class)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|