简体   繁体   中英

Accessing Bitset present inside a struct C++

I have a structure that looks like this :

struct bf_t {
bitset<250000> h0;
};

I want to know how to allocate memory for this struct and how to access h0 in my main() .

I tried doing this:

bf_t *b;
b->h0.set(1); 

error: base operand of ‘->’ is not a pointer

bf_t *b ;
b.h0.set(1); 

error: request for member ‘h0’ in ‘b’, which is of non-class type ‘long long int’

When you declare pointers like this bf_t *b; you have to assign to them before you use them. You probably want to create a new bf_t on the heap like this: b = new bf_t(); . Then you can use -> to access its members.

The error message and your code mismatch. However, it's much easier – you don't need pointers at all:

bf_t b;
b.h0.set(1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM