设为首页 加入收藏

TOP

C++自定义动态数组模板
2014-11-01 08:30:06 来源: 作者: 【 】 浏览:53
Tags:定义 动态 模板

  #include "stdafx.h"


  #include


  using namespace std;


  template


  class MyArray


  {


  int len;


  public:


  T *data;


  MyArray()


  {


  data = NULL;


  len = 0;


  }


  ~MyArray()


  {


  delete[] data;


  }


  T& operator [](int index);


  void push(T d);


  };


  template


  T& MyArray ::operator [](int index)


  {


  if(index<0||index>(len-1))


  {


  cout<<"Bad subscript!"<


  exit(1);


  }


  return data[index];


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++实现单链表逆序 下一篇cpp关于const和函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: