吓人的vector(stl)
来源:互联网 发布:java 判断法定节假日 编辑:程序博客网 时间:2024/04/25 11:36
运行一下下面的代码及知道了
#include <vector>
#include <set>
#include <list>
using namespace std;
class Fool
{
public:
Fool(){printf("this is construct in fool:%d/n",this);}
~Fool(){printf("this is disconstruct in the fool:%d/n",this);}
Fool(const Fool& other)//不管是赋值还是参数传递,调用的是这个,没有定义的话就调用默认的
{
printf("this is copy construct in fool:%d/n",this);
}
public:
Fool& operator=(const Fool& other)//???这个死活都是没被调用,调用的是拷贝构造函数,如果没被声明就调用默认的
{
printf("this is in operator'=':%d",this);
this->value=other.value;
return *this;
}
Fool& operator=(const int i)
{
this->value=i;
return *this;
}
private:
int value;
};
void FoolFunc()//这个函数执行结束的构造析构的次数就知道vector的性能,如果采用对象为元素,构造析构操作复杂时候更是性能问题
{
Fool a;
//Fool b=a;
//a=1;
vector<Fool> vecFool;
printf("push first/n");
vecFool.push_back(a);
printf("push second/n");
vecFool.push_back(a);
printf("push third/n");
vecFool.push_back(a);
printf("push forth/n");
vecFool.push_back(a);
printf("push fifth/n");
vecFool.push_back(a);
//vector<Fool> vecFool1;
//vecFool1=vecFool;
vecFool.clear();
}
void FoolFuncForSet()//set可以看作map的前面key部分,不可插入重复的key,查找效率高,这里使用的是key,所以不插入对象
{
Fool a;
set<Fool*> FoolSet;
FoolSet.insert(&a);
//FoolSet.insert(a);
//FoolSet.clear();
}
void FoolFuncForList()
{
list<Fool> ls;
Fool a;
printf("list insert first/n");
ls.insert(ls.begin(),a);
printf("list insert second/n");
ls.insert(ls.begin(),a);
printf("list insert second/n");
ls.insert(ls.begin(),a);
ls.clear();
}
int _tmain(int argc, _TCHAR* argv[])
{
FoolFunc();
//FoolFuncForSet();
//FoolFuncForList();
getchar();
return 0;
}
- 吓人的vector(stl)
- STL之vector的使用二(vector的遍历)
- STL之vector的使用三(vector的删除)
- STL之vector的使用一(初始化vector)
- 3.5 STL之vector的使用一(初始化vector)
- STL之Vector(一):Vector的基本用法
- STL之vector的使用(转载)
- STL vector<bool>的介绍(1)
- STL Vector的用法
- STL - vector的能力
- STL的Vector介绍
- STL的Vector
- STL的vector使用
- STL的vector
- STL vector 的用法
- STL-vector的实现
- STL --vector的介绍
- STL vector的复制
- Clone ZFS-based Solaris xVM domain
- 空间设计室
- 求救
- 安装.net时,无法安装 FrontPage 2000 WEB 扩展客户端解决办法
- CSDN英雄大会归来感悟
- 吓人的vector(stl)
- 消息称MySQL创始人已向Sun提交辞呈
- C#DOC批量转TXT工具
- 240个jQuery实现AJAX插件
- 使用正则表达式的方式重写URL。
- 如果不爱,请收起你的暧昧!
- 网站截图的原理——从服务器端模拟客户端
- javascript显示时间(在div中)
- map 转 bean