c++中vector问题

来源:互联网 发布:java数组学生管理系统 编辑:程序博客网 时间:2024/06/06 16:51
/**********************************************************************/
下面的这段程序是我学习vector模版时自己编的程序,编译连接通过后,提示内存错误,大家帮忙看看
#include <iostream>
#include <string>
#include <vector>
#include <conio.h>
#include <math.h>
#include "math.h"

using namespace std;

//test1类实现输入两个数x,y计算两者积,这部分没有错
class test1{
int x;
int y;
string ID;
public:
int z;
test1(string ID1="mmm",int x1=0,int y1=0,int z=0);
set(string ID1="mmm",int x1=0,int y1=0);
~test1();
void calculate(void);
string getID();
};

test1::test1(string ID1,int x1,int y1, int z1){
ID=ID1;
x=x1;
y=y1;
z=z1;
}
test1::set(string ID1,int x1,int y1){
ID=ID1;
x=x1;
y=y1;
}

test1::~test1()
{
}


void test1::calculate(void){
z=x*y;
}

string test1::getID(){
return ID;
}



//主函数使用了vector把设定的x,y以及ID的值存起来,然后从vector中调出这三个数进行计算
int main()
{

   test1 *test;
   vector<test1*> m_ptest2;           //向量模版


test=new test1;

   vector<test1>::iterator *it= m_ptest2.begin();


test->set("asdf",23,20);      
m_ptest2.push_back(test);

(*it)->calculate();                   //问题是不是出在这里????要怎么改

printf("%s,%d\n\n",(*it)->getID().c_str(),(*it)->z);


    return 0;
}
0 0