Answer the question
In order to leave comments, you need to log in
Segmentation Fault - Why?
There is a class:
class tree{
private:
vector<node> nodes;
vector<wstring> codedString;
int fmax;
int inode1;
int inode2;
public:
void extractString(wstring str); //Разделяем строку на первичные узлы
void construct();
void codeString (wstring str);
void printCodedString();
void printFreqTable();
void printCodeTable();
void codeNodes();
void code(node& n, int level);
void selectNode (wstring str);
wstring decodeString ();
void findCode (wstring str);
node findNode (wstring code);
bool inNodes (wstring str);
bool inNodes (int freq);
void getMinNode1();
void getMinNode2();
};
class node{
private:
int freq, child1, child2;
wstring sym;
wstring code;
bool flag;
public:
node(int fr, int ch1, int ch2, wstring s, wstring c):freq(fr),child1(ch1),child2(ch2),sym(s),code(c),flag(false){};
int getFreq();
int getChild1();
int getChild2();
wstring getCode();
//bool getFlag();
wstring getSym();
void incFreq();
void incCode(int val);
void toggle();
//bool operator> (node& n);
bool operator<= (node& n);
};
void tree::extractString (wstring str)
{
wcout << L"извлекаются узлы из строки" << endl;
for (int i=0; i<str.size()/2; i++){
wstring tmp = str.substr (i*2, 2);
if (inNodes(tmp)) selectNode(tmp);
else {
node n (1, -1, -1, tmp, L"");
nodes.push_back(n); //тут и возникает ошибка
}
}
wcout << L"узлы извлечены" << endl;
}
int main(){
setlocale (LC_ALL, "");
tree t;
wstring str;
wcout << L"Введите строку" <<endl;
getline(wcin, str);
t.extractString(str);
//и так далее
}
code
of the object node
has the type wstring
, as it is now, a segmentation error pops up in the function on the second node.Введите строку
Корабли лавировали, лавировали, да не вылавировали
извлекаются узлы из строки
Ошибка сегментирования (сделан дамп памяти)
int
(and at the same time changing the implementation of everything related to this field) - everything is successfully created, but this type is not suitable for my purposes. Answer the question
In order to leave comments, you need to log in
int is always passed by value unless told to be passed by reference.
What about vectors and strings? How do you think?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question