Object life time

Hello all,

I have the following class which is part of a big project, my problem is at some time during execution the member variables of this class are no more valid. I couldn't access them as I suppose they were destroyed before my application finishes execution.

Don't worry about what you haven't understood, I just need help about c++ part even if I am using two programming languages(C++ and OTcl) in my project.

#ifndef ns_dcdatabase_h
#define ns_dcdatabase_h
#include "stdlib.h"
#include "dbagent.h"
#include "dataobject.h"

class DcDatabase : public TclObject{
public:
DcDatabase();
virtual ~DcDatabase();
virtual int command(int argc, const char*const* argv);

void replicateData(DataObject* dObj);
void recvData(DataObject* recvDataObj);

protected:
DbComAgent* dcagnt;
vector<DataObject*>dcdata_list;
vector<ns_addr_t*> replicAddrList;
DataObject* dobj_;
int num;


};

#endif

#include "dcdatabase.h"

static class DcDatabaseClass : public TclClass{
public:
DcDatabaseClass() : TclClass("DcDatabase") {}
TclObject* create(int argc, const char*const*argv) {
return (new DcDatabase());
}
} class_dcdatabase;


DcDatabase::DcDatabase()
{

dcdata_list.clear();
replicAddrList.clear();
num=0;
dcagnt=NULL;
dobj_=NULL;
}

DcDatabase::~DcDatabase()
{
dcdata_list.~vector();
}


void DcDatabase::recvData(DataObject *dataObj)

{
// when I print something here it is Ok, the problem starts as soon as I access the member variables of these class.
Any member variable of these class whether they are user defined type or built in type like int are not valid in these member function.

Inside here when I check printf("data size %d\n",(int)dcdata_list.size()); it gives a wired negative values... I have gone through the rest of my project and reached this point where I couldn't proceed.
}


Last edited on
it gives a wired negative values...
That happens when DcDatabase object is invalid.

Remove this: dcdata_list.~vector();
you never call a destructor directly
Hello there I have tried that but didn't work.

I couldn't access member variables of these class inside its member function, it gives me "Segmentation fault". Apparently I have assigned values to these member variables and even checked by printing out after setting the values at the other point. Since I am running simulation I was wondering if the system destructs these variables before my application finishes execution.
if I do like the following, I will get segmentation fault inside recvData()

printf("num is%d \n", num);  


Any suggestions pls!
Last edited on
Hello there I have tried that but didn't work.
What?

You need to show the code where you use DcDatabase. You're doing something wrong with it
Topic archived. No new replies allowed.