lundi 29 mai 2017

What does "unhandled exception thrown: read access violation" mean?

I've been able to compile my code, but this exception keeps being thrown:

Unhandled exception thrown: read access violation. this->pExpr was 0xCCCCCCCC.

I've been able to narrow it down to the lines of code below, but I'm not quite sure how to go about fixing it.

Thank you in advance.

Code within header file

class AssignmentSTMT : public STMT
{
    string id;
    int varIx;
    EXPR * pExpr;
public:
    AssignmentSTMT(string id, int varIx, EXPR *pExpr) :
        id(id), varIx(varIx), pExpr(pExpr) {}
    string to_string() override
    {
        ostringstream os("");
        os << "assign " << id << " : " << varIx << " "<< " = " << pExpr->to_string();
        return os.str();
    }
};

Here's code within cpp file

EXPR* pExpr; // pointer to expression
 STMT* pStmt;

 expr(pExpr);   // initializes pExpr

    if (pExpr != nullptr)
    {
        // PROBLEM SUSPECTED HERE
        pStmt =  new AssignmentSTMT(pExpr); 
        RunTime::stmtTable.load(pStmt);
    }

Aucun commentaire:

Enregistrer un commentaire