views:

66

answers:

2

I have a class like this:

class OBJ{...};

class A
{
   public:
   vector<OBJ> v;
   A(int SZ){v.clear(); v.reserve(SZ);}
};

A *a = new A(123);
OBJ something;
a->v.push_back(something);

This is a simplified version of my code. The problem is in debug mode it works perfect. But in release mode it crashes at "push_back" line. (with all optimization flags OFF) I debugged it in release mode and the problem is in the constructor of A. the size of the vector is something really big with dummy values and when I clear it, it doesn't change...

Do you know why?

Thanks,

A: 

I can guess - I would say that OBJ probably does not have a correctly implemented copy constructor and/or assignment operator and destructor.

anon
OBJ has constructor, destructor, copy constructor, default constructor.My question is "Why the capacity of the vector is always something very big?" I used clear() and resize(0). didn't work..
Nima
@Nima The fact that it has these makes it even more likely that this is the problem. Post some real code.
anon
A: 

If it helps, here is some parts of the code:

  1. Here is when I push_back it to the vector:

    Mesh* mesh = new Mesh(vnum, 2*vnum);
    ...
    Face tempFace(index[0], index[1], index[2], readable/*r*/, false/*w*/);
    mesh->faces.push_back(tempFace);
    
  2. Here is the copy constructor:

    Face(const Face& f)
    {
        writable = f.writable;
        readable = f.readable;
        for(int i=0; i<3; i++)
        {
            e[i] = f.e[i];
            neigh[i] = f.neigh[i];
            v[i] = f.v[i];
        }
        valid = f.valid;
        if(f.Q!=NULL)
            Q = new SymMatrix( *(f.Q) );
        else
            Q=NULL;
    }
    
  3. And here is mesh constructor:

    Mesh::Mesh(int pNum, int fNum)
    {
        //Mesh::Mesh();
        points.clear();
        faces.clear();
        points.reserve(pNum);
        faces.reserve(fNum);
    }
    
Nima
Need more code and clues, Nima. What does the destructor do? Is Q initialized correctly in Face's other constructor? I'm sure you can figure out the code formatting. Also, I'm sure you can find out exactly where it crashes - where in push_back? You can use the debugger, log statements, etc. That would help.
Colin