将向量传递给函数后的释放错误

时间:2018-04-09 17:21:40

标签: c++ vector memory-management

的main.cpp

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <algorithm>
#include "Block.h"
#include "veclib.h"
#include "vector3d.h"
#include "concaveop.h"    

using namespace std;    

int main()
{

    //Defining variables    

    vector< vector<Block> > vertex,vertex1;
    vector<long double> polyz;
    vector<long double> polyy;
    vector<long double> polyx;  

    for(k=1;k<dimz+2;k++)
    {
    i[k]=1;

        cout<<"\n\n";

        str="y";

        cout<<"\n";

         while(str == "y" || str == "Y")
         {
          vertex[k].resize(i[k]+1);
          vertex1[k].resize(i[k]+1);

          if(i[k]==1)
          {cout<<"Enter the initial coordinates: ";
          cin>>vertex[k][i[k]].x>>vertex[k][i[k]].y>>vertex[k][i[k]].z;}    

            cout<<"\n\n"<<endl;

            if(str == "n" || str == "N")
            {break;}
            else
            {
            cout<<"Enter the coordinate vector of vertex "<<i[k]<<": ";

            cin>>vertex[k][i[k]].x>>vertex[k][i[k]].y>>vertex[k][i[k]].z;

            cout<<"\nTHE COORDINATES OF VERTEX "<<i[k]<<": ("<<vertex[k] 
            [i[k]].x<<","<<vertex[k][i[k]].y<<","<<vertex[k][i[k]].z<<")\n";
                //}
            }

          }

        //if(str == "n" || str == "N")
        //{break;}

        i[k]=i[k]+1;

    }

       polyx.resize(i[k]); polyy.resize(i[k]); polyz.resize(i[k]);

        //Transferring vertex coordinates

        for(j0=1;j0<i[k]+1;j0++)
        {polyx[j0]=vertex[k][j0].x; polyy[j0]=vertex[k][j0].y; polyz[j0]=vertex[k][j0].z;}

        divToBlocks(i[k],polyx,polyy,polyz);

        cout<<"\n"<<endl;

    }

    k=k-1;

 return 0;

}

执行代码后,发生以下错误。我认为这是一个解除分配的问题:

  Program received signal SIGTRAP, Trace/breakpoint trap.

在?? ()()         7 0x00435d54在__gnu_cxx :: new_allocator :: deallocate(这= 0x73f834,__ p = 0x2cb1310)在C:/ Program Files(x86)/CodeBlocks/MinGW/lib/gcc/mingw32/4.9.2/include/c ++ / ext / new_allocator .H:110         C:\ Program Files(x86)\ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 4.9.2 \ include \ c ++ \ ext \ new_allocator.h:110:3408:beg:0x435d54
        在C:\ Program Files(x86)\ CodeBlocks \ MinGW \ lib \ gcc \ mingw32 \ 4.9.2 \ include \ c ++ \ ext \ new_allocator.h:110

0 个答案:

没有答案