相关疑难解决方法(0)

使用shared_ptr的示例?

嗨,我今天问了一个问题,关于如何在同一个向量数组中插入不同类型的对象,我的代码就是那个问题

 gate* G[1000];
G[0] = new ANDgate() ;
G[1] = new ORgate;
//gate is a class inherited by ANDgate and ORgate classes
class gate
{
 .....
 ......
 virtual void Run()
   {   //A virtual function
   }
};
class ANDgate :public gate 
  {.....
   .......
   void Run()
   {
    //AND version of Run
   }  

};
 class ORgate :public gate 
  {.....
   .......
   void Run()
   {
    //OR version of Run
   }  

};      
//Running the simulator using overloading concept
 for(...;...;..)
 {
  G[i]->Run() ;  //will run …
Run Code Online (Sandbox Code Playgroud)

c++ boost smart-pointers vector shared-ptr

81
推荐指数
3
解决办法
16万
查看次数

标签 统计

boost ×1

c++ ×1

shared-ptr ×1

smart-pointers ×1

vector ×1