• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
demps_c
博客园    首页    新随笔    联系   管理    订阅  订阅
模板编程

template<class T,int i= 10>class a{
4 public:
5 a();
6 void printall();
7 private:
8 int size;
9 T *value;
10 };
11 template<class T,int i> a<T,i>::a(){
12 size = i;
13 value = new T [size];
14 }
15 template<class T,int i>void a<T,i>::printall(){
16 for(int j=0;j < size;j ++){
17 cout << value[j] << endl;
18 }
19 }
20 void f1(){
21 a<int,18> a1;//如果前面已经使用了int i= 10;则如果后面给出了参数,就使用后面的参数
22 a<short> a2;//如果后面没有使用参数就使用前面的参数i为10的
23 a1.printall();
24 a2.printall();
25 }

posted on 2013-10-03 10:44  demps_c  阅读(314)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3