Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Project2.exe中0x74A635D2处未处理的异常:Microsoft C++;异常:std::内存位置0x012FDBC4处的错误分配_C++_Pointers - Fatal编程技术网

C++ Project2.exe中0x74A635D2处未处理的异常:Microsoft C++;异常:std::内存位置0x012FDBC4处的错误分配

C++ Project2.exe中0x74A635D2处未处理的异常:Microsoft C++;异常:std::内存位置0x012FDBC4处的错误分配,c++,pointers,C++,Pointers,我创建了一个名为“Consulta Bool”的类,它应该创建一个树状结构。我使用这个类来进行布尔查询。这就是我创建类的原因(我有义务使用头文件和.cc文件),下面是头文件和.cc文件的代码: struct token { string tipo; string etq; Date fini, ffin; }; //(there is an endif here) class ConsultaBool { public: ConsultaBool(c

我创建了一个名为“Consulta Bool”的类,它应该创建一个树状结构。我使用这个类来进行布尔查询。这就是我创建类的原因(我有义务使用头文件和.cc文件),下面是头文件和.cc文件的代码:


struct token {
    string tipo; 
    string etq; 
    Date fini, ffin; 
};
//(there is an endif here)  

class ConsultaBool {
public:
    ConsultaBool(const string& s);
    ConsultaBool();
    ConsultaBool(const Date& fini, const Date& ffin); 
    ConsultaBool AND(ConsultaBool q2); 
    ConsultaBool OR(ConsultaBool q2);  
    ConsultaBool NOT();                       
    void read(istream& is);
    ConsultaBool getEsquerra();
    ConsultaBool getDreta();
    token getToken();

private: 
    token arrel;
    ConsultaBool* dreta; //dreta mins right side of the Bin Tree
    ConsultaBool* esquerra; //esquerra means left side 
};

(there is another endif here)'''```

and here comes the heavy stuff;


string toUpper(const string& s) {
    string res = "";
    for (int i = 0; i < s.length(); ++i)
        res += toupper(s[i]);
    return res;
}

void read_input(istream& is, vector<token>& l);
int precedence(string oper);
void convert_infix_to_postfix(const vector<token>& infix, vector<token>& postfix);
ConsultaBool construct_bool_query(const vector<token>& postfix);

ConsultaBool::ConsultaBool(const string& s) {
    this -> arrel.etq = s;
    this -> arrel.tipo = "TAG";
}

ConsultaBool::ConsultaBool(const Fecha& fini, const Fecha& ffin) {
    this ->arrel.fini = fini;
    this ->arrel.ffin = fini;
    this ->arrel.tipo = "DATE";
} 

ConsultaBool::ConsultaBool() {
    this->arrel.tipo = "#";
} 

token ConsultaBool::getToken() {
    return arrel;
}

ConsultaBool ConsultaBool::getDreta() {
    return *dreta;
}

ConsultaBool ConsultaBool::getEsquerra() {
    return *esquerra;
}
ConsultaBool ConsultaBool::AND(ConsultaBool q2) {
    ConsultaBool consulta;
    consulta.arrel.tipo = "AND";
    consulta.dreta = this;
    consulta.esquerra = &q2;
    return consulta;
} 

ConsultaBool ConsultaBool::OR(ConsultaBool q2) {
    ConsultaBool consulta;
    consulta.arrel.tipo = "OR";
    consulta.dreta = this;
    consulta.esquerra = &q2;
    return consulta;
}  

ConsultaBool ConsultaBool::NOT() {
    ConsultaBool consulta;
    consulta.arrel.tipo = "NOT";
    consulta.esquerra = this;
    return consulta;
}                       

ConsultaBool construct_bool_query(const vector<token>& postfix) {
    stack<ConsultaBool> S;
    for (int i = 0; i < postfix.size(); ++i) {
        token tk = postfix[i];
        if (tk.tipo == "TAG") S.push(ConsultaBool(tk.etq)); 
        if (tk.tipo == "DATE") S.push(ConsultaBool(tk.fini, tk.ffin)); 
        if (tk.tipo == "AND" or tk.tipo == "OR") {
            ConsultaBool q2 = S.top(); S.pop();
            ConsultaBool q1 = S.top(); S.pop();
            if (tk.tipo == "AND") S.push(q1.AND(q2)); 
            if (tk.tipo == "OR") S.push(q1.OR(q2)); 
        }
        if (tk.tipo == "NOT") {
            ConsultaBool q = S.top(); S.pop(); 
            S.push(q.NOT()); // apila una consulta 'not q'
        }
    }
    return S.top();
}

ConsultaBool::read(istream& is) {

    vector<token> infix, postfix;
    read_input(is, infix);
    if (infix.empty()) { 
        *this = ConsultaBool(); 
        return; 
    }
    convert_infix_to_postfix(infix, postfix);
    *this = construct_bool_query(postfix);
}

void read_input(istream& is, vector<token>& l) {
    string s; 
    is >> s; 
    while (s != "END_QUERY") {
        token tk;
        s = toUpper(s);
        tk.tipo = s;
        if (s == "(" or s == ")" or s == "AND" or s == "OR" or s == "NOT") { 
            l.push_back(tk);
        }
        if (s == "DATE") { /** usad el metodo Fecha::llegir() o similar si no teneis
                            sobrecargado el operador >> para leer fechas **/
            tk.fini.lee_fecha();
            tk.ffin.lee_fecha();
            l.push_back(tk);
        }
        if (s == "TAG") {
            is >> tk.etq;
            l.push_back(tk);
        }      
        is >> s;
    }
}

/**THEORETICALLY FROM THIS POINT ON EVERYTHING SHOULD BE CORRECT **/

int precedence(string oper) {
    if (oper == "OR") return 1;
    if (oper == "AND") return 2;
    if (oper == "NOT") return 3;
    return 0;
}

void convert_infix_to_postfix(const vector<token>& infix, vector<token>& postfix) {
    stack<token> S;
    token spc; spc.tipo = "#"; S.push(spc);
    for (int i = 0; i < infix.size(); ++i) {
        token tk = infix[i];
        if (tk.tipo == "DATE" or tk.tipo == "TAG")
            postfix.push_back(tk);
        else if (tk.tipo == "(" or tk.tipo == "NOT") 
            S.push(tk);
        else if (tk.tipo == ")") {
            while (S.top().tipo != "#" and S.top().tipo != "(") {
                postfix.push_back(S.top()); S.pop();
            }
            S.pop();
        } else {
            while (S.top().tipo != "#" and 
                precedence(tk.tipo) <= precedence(S.top().tipo)) {
                    postfix.push_back(S.top()); S.pop();
            }
            S.push(tk);
        }
    }
    while (S.top().tipo != "#") {
        postfix.push_back(S.top()); S.pop();
    } 
}

结构令牌{
弦梯坡;
字符串etq;
日期:菲尼,ffin;
};
//(这里有一个endif)
类顾问工具{
公众:
ConsultaBool(常量字符串和字符串);
ConsultaBool();
领事馆(施工日期和完工日期、施工日期和ffin);
ConsultaBool和(ConsultaBool q2);
ConsultaBool或(ConsultaBool q2);
ConsultaBool NOT();
无效读取(istream&is);
ConsultaBool getEsquerra();
ConsultaBool getDreta();
令牌getToken();
私人:
象征性阿雷尔;
ConsultaBool*dreta;//dreta分钟在垃圾箱树的右侧
ConsultaBool*esquerra;//esquerra表示左侧
};
(这里还有一个endif)“”```
沉重的东西来了;
字符串插入器(常量字符串&s){
字符串res=“”;
对于(int i=0;iarrel.etq=s;
此->arrel.tipo=“TAG”;
}
ConsultaBool::ConsultaBool(const Fecha&fini,const Fecha&ffin){
此->arrel.fini=fini;
此->arrel.ffin=fini;
此->arrel.tipo=“日期”;
} 
ConsultaBool::ConsultaBool(){
此->arrel.tipo=“#”;
} 
令牌ConsultaBool::getToken(){
返回arrel;
}
ConsultaBool ConsultaBool::getDreta(){
返回*德雷塔;
}
ConsultaBool ConsultaBool::getEsquerra(){
返回*埃斯奎拉;
}
ConsultaBool ConsultaBool::AND(ConsultaBool q2){
领事馆;
consulta.arrel.tipo=“和”;
consulta.dreta=这个;
consulta.esquerra=&q2;
返回顾问;
} 
ConsultaBool ConsultaBool::OR(ConsultaBool q2){
领事馆;
consulta.arrel.tipo=“或”;
consulta.dreta=这个;
consulta.esquerra=&q2;
返回顾问;
}  
ConsultaBool ConsultaBool::NOT(){
领事馆;
consulta.arrel.tipo=“不”;
consulta.esquerra=此;
返回顾问;
}                       
ConsultaBool构造布尔查询(常量向量和后缀){
堆栈S;
对于(int i=0;i>s;
而(s!=“结束查询”){
代币tk;
s=toUpper(s);
tk.tipo=s;
如果(s==”(“或s==”)或s==”和“或s==”或“或s==”不是”){
l、 推回(tk);
}
如果(s==“DATE”){/**usad el-metodo-Fecha::llegir()类似
sobrecargado el operador>>帕拉·里尔·费查斯**/
tk.fini.lee_fecha();
tk.ffin.lee_fecha();
l、 推回(tk);
}
如果(s==“标记”){
is>>tk.etq;
l、 推回(tk);
}      
是>>s;
}
}
/**从理论上讲,从这一点上讲,一切都应该是正确的**/
int优先级(字符串操作){
if(oper==”或“)返回1;
if(oper==”和“)返回2;
如果(oper==“NOT”),返回3;
返回0;
}
void将中缀转换为后缀(常量向量和中缀、向量和后缀){
堆栈S;
令牌spc;spc.tipo=“#”S.push(spc);
对于(int i=0;i优先权(tk.tipo)
consulta.esquerra=&q2;
的两种用法都取局部变量的地址,该变量在函数结束后停止存在。即使使用了
ConsultaBool&q2
它也会改变问题,因为
看起来只是对局部变量调用。基本问题是我想使用任何动态分配来创建树,但是您使用了局部变量的地址作为树中的指针。除非我遗漏了什么,否则您不会使用
new
delete
、智能指针等。