Advertisement
triclops200

dynamic reallocation classes

Jul 14th, 2011
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2.     class dynamic{
  3.     public:
  4.         template<class T> void recast(){
  5.             redo<T>(this);         
  6.         }
  7.         template<class T>void redo(dynamic* x){
  8.             delete this;
  9.             x = new T;         
  10.         }
  11.         virtual void call(void) =0;    
  12.     };
  13.     class inherited : public dynamic{
  14.         void call(void){
  15.             std::cout<<"works!"<<std::endl;
  16.         }  
  17.     };
  18. int main(int argc, char* argv[]) {
  19.     dynamic *d = new inherited;
  20.     for(int i =0; i<227000;i++){   
  21.         d->recast<inherited>();
  22.     }
  23.     d->call();
  24.    return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement