knightL

Example

May 30th, 2011
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <class T>
  5. class A
  6. {
  7.     T a;
  8. public:
  9.     A(T _a): a(_a){}
  10.     void print(){cout<<a<<endl;}
  11. };
  12.  
  13. template <class T>
  14. class B: public A<T>
  15. {
  16.     int v;
  17. public:
  18.     B(T a,int _v): A<T>(a), v(_v) {}
  19.     void print(){for(int i=0;i<v;i++) A<T>::print();}
  20. };
  21.  
  22. int main()
  23. {
  24.     B <double> v(3.5,2);
  25.     v.print();
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment