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

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 9  |  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. Base class template instantiation depending on derived class constructor argument type
  2. template <class T>
  3. class foo
  4. {
  5. int a;
  6. public:
  7.     foo(T a){}
  8.     // When I convert the constructor to a function template, it works fine.
  9.     // template <typename T> foo(T a){}
  10. };
  11.  
  12. class bar : public foo<class T>
  13. {
  14. public:
  15.     bar(int a):foo(a){}
  16. };
  17.  
  18. int main(void)
  19. {
  20.     bar obj(10);
  21.     system("pause");
  22.     return 0;
  23. }
  24.        
  25. template<class T>
  26. class bar : public foo<T>
  27. {
  28. public:
  29.     bar(int a):foo(a){}
  30. };
  31.  
  32.  
  33. int main()
  34. {
  35.     bar<int> obj(10);
  36. }
  37.        
  38. class bar : public foo<int>
  39. {
  40. public:
  41.     bar(int a):foo(a){}
  42. };
  43.  
  44.  
  45. int main()
  46. {
  47.     bar obj(10);
  48. }