返回   cpper编程论坛 > 技术杂烩
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

技术杂烩 找不到地方的技术问题?这里!

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2002-09-30
初级会员
 
注册日期: 2002-09-13
帖子: 29
uniqlo1 正向着好的方向发展
默认 <primer> 第6章 vector 型的容量 capacity()函数

此函数与size()函数有哪些不同,我有点看不懂,请指教一二。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2002-09-30
abp 的头像
abp abp 当前离线
高级会员
 
注册日期: 2002-08-30
帖子: 811
abp 正向着好的方向发展
默认

一个vector如果有5个元素的话,它占用的内存可能超过5个元素,譬如说10个。
那么size()返回5,capacity()返回10。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2002-09-30
高级会员
 
注册日期: 2002-09-16
帖子: 1,087
文章: 1
SpitFire 正向着好的方向发展
默认

size返回的是该vector中的元素个数,而capacity()返回的是vector的容量
就像一个杯子,杯子中有多少水是size,杯子最多能装多少水是capacity
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2002-09-30
初级会员
 
注册日期: 2002-09-13
帖子: 29
uniqlo1 正向着好的方向发展
默认

:P 谢谢。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2002-10-01
初级会员
 
注册日期: 2002-09-13
帖子: 29
uniqlo1 正向着好的方向发展
默认

还有一个问题就是虚数的类<complex>中有无求倒数的函数或运算符?
如果没有我自己定义一个<my_complex>的时候,重载那个运算符去求
倒数好呢?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2002-10-01
abp 的头像
abp abp 当前离线
高级会员
 
注册日期: 2002-08-30
帖子: 811
abp 正向着好的方向发展
默认

A的倒数应该等于1/A。不知道complex支持不支持除法????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2002-10-11
高级会员
 
注册日期: 2002-09-10
帖子: 269
文章: 1
panda 正向着好的方向发展
发送 MSN 消息给 panda
默认

代码:
#include <iostream> #include <vector> using namespace std; int main(void) { int i = 0; vector<int> test; for (int i = 0; i < 5; i++) { test.push_back(i + 1); } vector<int>::size_type capacity = test.capacity(); cout << capacity << endl; return 0; }
代码一开始没有指定vector的大小,当你不断push_back的时候,vector会自动调整capacity,大小是2的指数倍往上翻。size指的是容器内元素的个数,而capacity是指容器的大小。我用的是sgi的stl,这里push了5个元素后,capacity调整成了8。如果push了10个元素,就是16
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 11:23 PM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2009,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0