c++ - dynamic bitset initialized and called from other method gives segmentation fault -


I am initializing a dynamic bitset in a class constructor and then filling it with some values ​​that square Call a method of: I get a split mistake, it does not matter what bitset I want to use. MyClass :: MyClass () {boost :: dynamic_bitset & lt; & Gt; Occupation (200000); // all 0 by default std :: cout & lt; & Lt; Occupancy.size () & lt; & Lt; "\ N"; Std :: cout & lt; & Lt; Occupation [1234] & lt; & Lt; "\ N"; Fill_occupancy (); } Zero MyClass :: fill_occupancy () {std :: cout & lt; & Lt; Occupation [1234] & lt; & Lt; "\ N"; }

The printer prints 200000 and 0 correct output, but when entering the fill_occpancy method, it returns a siffault.

I checked it, but I do not think it is applicable, BC produces bits properly because I see the correct output from the constructor.

I have found a way to do this work if I just use method__bitset type & gt; & Gt; And then call it to fill it (occupancy). Why does this work and not code up? Other data types I can call in other ways without argument.

Thank you.

Edit Anyone interested will be more detailed Detailed:

  class MyClass () {boost :: dynamic_bitset & lt; & Gt; Occupancy; // call default bosset constructor (i.e. size 0)}   

in the MyCalce constructor, just calling

  MyClass :: MyClass () {occupancy (200000) ; // this is false}   

causes an error because the occupancy is set to zero size. To change its size, someone has to call

  MyClass :: MyClass () {occupancy.resize (200000); // this is correct}   

Then occupancy size is correct and it is a member of MyClass and like fill_occupancy () class .

My original creation worked as a member of a local variable in the possession of a local variable in such a constructor, but the member (size 0) was called everywhere, which was called the signfault

Check again for clarification Thanks.

Consortor local by the name of the occupation Known, there is no data member of the same name:

  Promotion: Dynamic_bit  & Gt; Occupation (200000); // local variable   

It seems that you want to start a data member, which you can do:

  MyClass :: MyClass (): Occupation (200000) {std :: cout & lt; & Lt; Occupancy.size () & lt; & Lt; "\ N"; Std :: cout & lt; & Lt; Occupation [1234] & lt; & Lt; "\ N"; Fill_occupancy (); }    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -