c++structboost-dynamic-bitset

How to introduce dynamic_bitset in a struct


I tried to use dynamic_bitset in a structure. The size of u depends on the input.

#include <boost/dynamic_bitset.hpp>

struct myStruct
{
    double x;
    boost::dynamic_bitset<> u();
    myStruct( double a, boost::dynamic_bitset<>& v ) : x( a ), u( v ) {}
    {
        // some lines here
    }
};

However, I get the following error while compiling the code:

error: class ‘myStruct’ does not have any field named ‘u’

How can I solve this issue? Thank you in advance.


Solution

  • You have declared u as a function prototype (i.e. a function returning a dynamic_bitset) rather than a member variable.

    Change:

    boost::dynamic_bitset<> u();
    

    to:

    boost::dynamic_bitset<> u;