STL 里面 SET使用 遇到的问题

zqz981 2011-02-15 05:00:27
在一个类里面使用了set 做容器, 结果出现了奇怪的情况,
容器为空的情况下出现了一下异常情况:

容器为空, 但是自动的容量变得超级大。
非指针类型的set 如何初始化保证set为空啊?
...全文
225 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hiei1234 2011-02-17
  • 打赏
  • 举报
回复
绝对不是set的问题
zqz981 2011-02-17
  • 打赏
  • 举报
回复

源代码太多, 说不清楚, 我展示的是debug时候看到的信息。抱歉, 前两天没来得及回帖看
elegant87 2011-02-17
  • 打赏
  • 举报
回复

// constructing sets
#include <iostream>
#include <set>
using namespace std;

bool fncomp (int lhs, int rhs) {return lhs<rhs;}

struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return lhs<rhs;}
};

int main ()
{
set<int> first; // empty set of ints

int myints[]= {10,20,30,40,50};
set<int> second (myints,myints+5); // pointers used as iterators

set<int> third (second); // a copy of second

set<int> fourth (second.begin(), second.end()); // iterator ctor.

set<int,classcomp> fifth; // class as Compare

bool(*fn_pt)(int,int) = fncomp;
set<int,bool(*)(int,int)> sixth (fn_pt); // function pointer as Compare

return 0;
}
loveanybody 2011-02-15
  • 打赏
  • 举报
回复
图片无法链接 兄弟把代码一帖更快一些
LinkSe7en 2011-02-15
  • 打赏
  • 举报
回复
无法访问 好吧

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧