#include <iostream>
#include <string>
#include <array>
using namespace std; class Object{
public:
virtual void ToString(){
cout<<"Object"<<endl;
} public:
virtual int GetPtrLength(){
return sizeof(this);
}
}; class Test : public Object{
public:
void ToString(){
cout<<"Test"<<endl;
}
}; class Ptr{
public:
char Bytes[];
}; class Int32{
public:
int m_Value;
public:
int GetPtrLength(){
return sizeof(Int32);
}
}; template <class T>
class List{
public:
List() { m_Count=; m_Array = new char*[]; }
~List(){ if(m_Array!=NULL) { delete[] m_Array; cout<< "释放数组指针"<<endl; }
} private:
int m_Count;
char** m_Array; public:
void Add(T* item){
((Object**)m_Array)[m_Count]=(Object*)item;
m_Count++;
}
Object* operator[](int i)
{
if(i >= m_Count)
throw "索引超过最大值";
return ((Object**)m_Array)[i];
} }; int main(){
try{
////初始化一个 指针数组
//Object** aaaa =NULL;
//aaaa = new Object*[1000];
//aaaa[0]=new Object(); //cout<< sizeof(Ptr)<<endl;
//cout<<*(new int(1000000))<<endl; //char bytes[20];
//int* v0 = (bytes[0]);
//bytes[0] = *(new int(1000000));
//bytes[4] = *(new int(2000000));
//for(int i=0;i<20;i++)
// cout<< bytes[i];
//cout<<endl; //cin.get();
//return 0; List<Object> list;
list.Add(new Object());
list.Add(new Test());
auto ptr = list[];
ptr->ToString(); //Test
//delete list; List<int> list2;
list2.Add(new int());
list2.Add(new int());
auto ptr2 = list2[];
ptr2->ToString(); //崩溃 }catch(char* str){
cout<< str << endl;
}catch(...){
cout<<"未知异常"<<endl;
} cin.get();
return ;
}

执行结果

 Test
程序崩溃

最新文章

  1. 制造行业流程管理的“IPO”思维
  2. Java多线程系列--“JUC锁”06之 Condition条件
  3. .net程序员转行做手游开发经历(一)
  4. Ubuntu 12.10安装OpenGL
  5. URAL 1018 Binary Apple Tree(树DP)
  6. Cocos2d-x第一个坑,NDK 编译环境
  7. Cannot open your terminal &#39;/dev/pts/4&#39; - please check.
  8. node-koa搭建MVC/RESTful API项目
  9. Android图表库MPAndroidChart(十三)——简约的底部柱状图
  10. C#接口的简单创建及其用法
  11. 用户代码与Spring的交互形式,你有总结过吗?
  12. set用法
  13. Android_Printservice_API_部分翻译
  14. 学号 20175223 《Java程序设计》第2周学习总结
  15. 【多线程】Task
  16. 安装连接mysql8时候遇到的问题以及解决(转)
  17. Eclipse svn 项目 星号
  18. 解决git中文乱码问题
  19. mongodb基础学习13-聚集aggregate操作
  20. pH计

热门文章

  1. Unity --- 关节组件
  2. 通过JTS源码分析Rtree(未完待续)
  3. maoaolianxi
  4. Vue2.0中的Ajax请求
  5. Appium 常用方法
  6. Linq中使用Left Join 和 Right Join
  7. 在ubuntu16.04上安装eclipse
  8. commons.pool2 对象池的使用
  9. Apache Commons-logging使用实例
  10. PHP中__get()和__set()的用法实例详