Questions of boost bitset

C

ctick

Q1.
boost::dynamic_bitset<>& get_bset()
{
boost::dynamic_bitset<> x(8);
return x;
}

void main()
{
boost::dynamic_bitset<> y(8);
y = get_bset();
}

Does y have to be specified with size, like 8 in main()?

Q2.
If there are two dynamic_bitset,

boost::dynamic_bitset<> x(8);
boost::dynamic_bitset<> y(8);

How to copy all bits from x to y?

Q3.
What will happen if copying from x from y but they have different size of
bits?

boost::dynamic_bitset<> x(10);
boost::dynamic_bitset<> y(8);

Thanks in advance!
 
D

David Harmon

On Sat, 19 Jun 2004 18:36:55 GMT in comp.lang.c++, "ctick"
Q1.
boost::dynamic_bitset<>& get_bset()
{
boost::dynamic_bitset<> x(8);
return x;
}

A1. Wrong.
You are returning a reference to a local variable that will have been
destroyed before it can be used. You probably want to return by value
here.
void main()
{

A2. void main() is wrong. main() must always return int.
boost::dynamic_bitset<> y(8);
y = get_bset();
}

Does y have to be specified with size, like 8 in main()?

A3. No. y will get the size of the dynamic_bitset that you later
assign to it.

Q2.
If there are two dynamic_bitset,

boost::dynamic_bitset<> x(8);
boost::dynamic_bitset<> y(8);

How to copy all bits from x to y?

y = x;
Q3.
What will happen if copying from x from y but they have different size of
bits?

boost::dynamic_bitset<> x(10);
boost::dynamic_bitset<> y(8);

y will get the size of the dynamic_bitset that you assign to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top