Template Template Parameter

///////////////////////////////////////////////////////////////////
// TTP.h: a simple example for demonstrating template template parameter
// Author: Yu Zhang
// Org: Syracuse University
// Contact: 315-314-0228
///////////////////////////////////////////////////////////////////

#include <iostream>
using namespace std;

template <typename T>
class Cloner{
 public:
  T* clone(T& t)
  {
    cout<<"I am clonning for the lazy boy\n";
    return new T(t);
  }

};

template <typename C, class D>
  class LazyCloner:public D{
 public:
  C* LazyClone(C& Cloned)
  {
    cout<<"I am lazy, I just want my cloner to do it.\n";
    return D::clone(Cloned);
  }

};

--------------------------------------------------------------------------------

////////////////////////////////////////
// Test_main.cpp: tests TTP package
///////////////////////////////////////

#include "TTP.h"
#include <vector>
#include <iostream>
using namespace std;


int main(){
  int i = 9;
  LazyCloner< int, Cloner<int> > LC;
  int *pInt =  LC.LazyClone(i);
  cout<<"Original number is "<<i<<endl;
  cout<<"Copied number is "<<*pInt<<endl;
  return 0;

}

----------------------------------------------------------
output:
----------------------------------------------------------
I am lazy, I just want my cloner to do it.
I am clonning for the lazy boy
Original number is 9
Copied number is 9

Comments

Popular Posts