【ThinkingInC++】44、编译期间类里的常量
来源:互联网 发布:3阶魔方矩阵 编辑:程序博客网 时间:2024/05/03 21:31
/*** 书本:【ThinkingInC++】* 功能:编译期间类里的常量* 时间:2014年9月10日08:32:56* 作者:cutter_point*/#include<cstring>#include<iostream>using namespace std;class StringStack{ static const int size=100; //所有的对象共享且不变的数据 const string* stack[size]; int index;public: StringStack(); void push(const string* s); const string* pop();};StringStack::StringStack():index(0){ //包含在cstring头文件中(C++)而在C中是string.h(C)头文件 //加了个.h代表涵盖了using namespace std; memset(stack, 0, size*sizeof(string*)); //吧数组Stack全部初始化}void StringStack::push(const string* s){ if(index < size) stack[index++]=s;}const string* StringStack::pop(){ if(index > 0) { const string* rv=stack[--index]; //初始化,这里用const是为了返回值 stack[index]=0; return rv; //返回给函数 } return 0;}string iceCream[]={ "pralines & cream", "fudge ripple", "cutter_point", "wild mountain blackberry", "raspberry sorbet", "lemon swirl", "rocky road", "deep chocolate fudge"};const int iCsz=sizeof(iceCream)/sizeof(*iceCream); //求得iceCream里面string的个数int main(){ StringStack ss; for(int i=0 ; i<iCsz ; ++i)// void push(const string* s); ss.push(&iceCream[i]); const string* cp; while((cp=ss.pop()) != 0) cout<<*cp<<endl; return 0;}
0 0
- 【ThinkingInC++】44、编译期间类里的常量
- 【ThinkingInC++】42、类里的const
- 类里面的const:编译期间的变量和常量
- 类里面的const:编译期间的变量和常量
- C++编译期间类中的常量
- C++编译期间类中的常量
- 常量和变量在编译期间的行为
- ActionSupport类里的常量
- 【ThinkingInC++】43、内建类型封装在一个类里
- 【ThinkingInC++】46、特定的数据成员可以在一个const对象里被改变
- 在编译期间获取类型的信息
- constexpr 进行编译期间的字符串加密
- 【ThinkingInC++】3、文件的拷贝
- 【ThinkingInC++】10、全局变量的使用
- 【ThinkingInC++】28、public的作用
- 【ThinkingInC++】35、重载的例子
- 【ThinkingInC++】60、嵌入的迭代器
- 【ThinkingInC++】32、一个句柄类
- iOS:内存管理
- 你真的会和异性聊天吗?
- HDU 3472 HS BDC 混合图欧拉回路 网络流
- 电脑每次开机都检测硬盘
- 前端工程师必备-网址篇(持续完善中)
- 【ThinkingInC++】44、编译期间类里的常量
- 20140910 N2
- NavigationController 的view 之间切换的实现功能
- 【ThinkingInC++】45、比较const和非const成员函数的例子
- 女友让我走上家具电商年入亿万之路
- Mr. Process的一生-Linux内核的社会视角 (1)调度
- struts1.2 struts-config.xml配置
- WebView实现文件下载功能
- 设计模式观后(c++还原之六 虚拟工厂)