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;
}
下面的这段程序是我学习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
- c++(vector)问题
- vector中指针问题
- c++中vector问题
- vector中size问题
- 【c++】vector.clear()的内存泄露问题
- C++中vector的用法
- C++中vector的用法
- C++STL中vector容器的用法
- c++ vector中插入pair
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- C++STL中vector的使用
- C++STL中Vector常用函数
- C++STL中vector容器的用法
- C++STL中vector容器的用法
- 自己做IE各个版本兼容的时候用的解决办法方法,IE6到IE11都可以【亲测】
- CString和WCHAR数组相加出现了问题,请各位回答一下,谢谢!
- hdu 1358 Period(next数组的理解)
- Wince系统程序-数组内存分配
- fedora Chrome出现adobe flash is out of date的解决方法
- c++中vector问题
- Android拨打电话等功能实现及其延伸
- MFC 启动exe 参数传递
- 多线程操作全局变量的问题(有点复杂,需要考虑线程的优先级问题)
- hdu 2594 Simpsons' Hidden Talents(KMP)
- Docker学习总结之Run命令介绍
- stl算法设计理念_预定义函数对象和函数适配器1
- MFC的一个简单问题
- 深入 Composer autoload