Sorry hit reply too early. Answer below.
"ctick" <ct***@flare.com> wrote in message
news:fq***************@bgtnsc05-news.ops.worldnet.att.net...
I try to make a member of "dynamic_bitset" of a dynamic size that is
determined when its containing class is instantiated. The code has error
when compiling: "N is undefined" something like that. Obviously, N is
defined before x!
Does anyone know how to solve the problem?
Thanks in advance!
class bset
{
private:
int N;
boost::dynamic_bitset<> x(N);
Lose the (N)
boost::dynamic_bitset<> x;
public:
bset(int n);
};
bset::bset() : N(n)
Replace with this
bset::bset() : N(n), x(n)
{
}
Strange one, you knew you could write N(n), but you didn't know to write
x(n)?
Another point, there is no need to store the size separately, if you want
the size of a dynamic_bitset you can just say x.size(). If you store the
size separately you are wasting space and even more importantly there is
always the chance that the size of the bitset and the size in N will get out
of step.
So change the code to this
class bset
{
private:
boost::dynamic_bitset<> x;
public:
bset(int n);
int get_size() const;
};
bset::bset(int n) : x(n)
{
}
int bset::get_size() const
{
return x.size();
}
john