VS 2008 Vector 数组奇怪事情

 

//类文件

 

class BoundSalesMan :

{

vector<vector<int> >  matrix; //对应的邻接矩阵

vector<int> path; //记录走过的最小成本路径

public:

BoundSalesMan(int citycount)

{

path.resize(citycount-1);

srand((unsigned)time(NULL));

 

for (int i=0;i<citycount;i++)

{

vector<int> col;      

for (int j=0;j<citycount;j++)

{

int num=rand()%100;

col.push_back(num);

}

matrix.push_back(col);

}

}

}

 

//主函数文件中使用

 

BoundSalesMan bsm(k);

 

如果使用debug版则主函数执行完上一句后matrix仍然存在值

而如果使用release版则主函数执行完上一句之后matrix中值不存在了。

 

难道是因为col为临时变量,而push_back传递的是引用的问题?

 

在debug版本下,col的内存没有被释放,而在release版下被释放的的缘故吗?

 

但是如果是这样的话path的size为什么也和传进来的参数citycount-1不相同啊。path的size居然上亿!!!!

 

你可能感兴趣的:(vector,null,Class,Path,Matrix)