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. 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: in the MyCalce constructor, just calling causes an error because the occupancy is set to zero size. To change its size, someone has to call Then occupancy size is correct and it is a member of MyClass and like 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 It seems that you want to start a data member, which you can do: 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"; }
class MyClass () {boost :: dynamic_bitset & lt; & Gt; Occupancy; // call default bosset constructor (i.e. size 0)}
MyClass :: MyClass () {occupancy (200000) ; // this is false}
MyClass :: MyClass () {occupancy.resize (200000); // this is correct}
fill_occupancy ()
occupation Known, there is no data member of the same name:
Promotion: Dynamic_bit & Gt; Occupation (200000); // local variable
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
Post a Comment