Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C  , polymorphism vs. templatization of a function argument
  2. template <typename T>
  3. class A {T a;};
  4.  
  5. template <typename T>
  6. class B: public A <T> {T b;};
  7.        
  8. template <typename Item>
  9. struct TItems {typedef std::vector <Item> Type;};
  10.  
  11. template <typename Item>
  12. class ModCont
  13. {
  14.     private:
  15.             typename TItems <Item>::Type items;
  16. };
  17.        
  18. template <typename T>
  19. void test ( ModCont <A <T> > *it) {}
  20.        
  21. int main(int argc, char* argv[])
  22. {
  23.  
  24.   ModCont < A <double> > a_items;
  25.   ModCont < B <double> > b_items;
  26.   test (&a_items); //Works
  27.   test (&b_items); //Does not work
  28.   return 0;
  29. }
  30.        
  31. template <typename Object>
  32. void test ( ModCont <Object> *it) {}