Object does not exist after constructor?

Posted by openbas on Stack Overflow See other posts from Stack Overflow or by openbas
Published on 2010-04-03T10:12:33Z Indexed on 2010/04/03 10:13 UTC
Read the original article Hit count: 281

Hello,

I have a constructor that looks like this (in c++):

Interpreter::Interpreter() {
        tempDat == new DataObject();
        tempDat->clear();
}

the constructor of dataObject does absolutely nothing, and clear does this:

bool DataObject::clear() {
        //clear the object

        if (current_max_id > 0) {
            indexTypeLookup.clear();
            intData.clear();
            doubleData.clear();
            current_max_id = 0;
        }

}

Those members are defined as follows:

std::map<int, int> indexTypeLookup;
std::map<int, int> intData;
std::map<int, double> doubleData;

Now the strange thing is that I'm getting a segfault on tempDat->clear(); gdb says tempDat is null. How is that possible? The constructor of tempDat cannot fail, it looks like this:

DataObject::DataObject() : current_max_id(0)
{

}

I know there are probably better way's of making such a data structure, but I really like to know where this segfault problem is coming from..

© Stack Overflow or respective owner

Related posts about c++

Related posts about constructor