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

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 14  |  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  : partial specialization of template template classes
  2. using namespace std;
  3.  
  4. template <typename X>
  5. class Goo {};
  6.  
  7.  
  8. template <typename X>
  9. class Hoo {};
  10.  
  11.  
  12. template <class A, template <typename> class B = Goo >
  13. struct Foo {
  14.   B<A> data;
  15.   void foo1();
  16.   void foo2();
  17.  
  18. };
  19.  
  20.  
  21. template <typename A>
  22. void Foo<A>::foo1() { cout << "foo1 for Goo" << endl;}
  23.  
  24.  
  25. int main() {
  26.   Foo<int> a;
  27.   a.foo1();
  28.  
  29. }
  30.        
  31. test.cc:18: error: invalid use of incomplete type 'struct Foo<A, Goo>'
  32. test.cc:11: error: declaration of 'struct Foo<A, Goo>'
  33.        
  34. template <>
  35. void Foo<int, Goo>::foo1() { }  // OK
  36.        
  37. template <typename A>
  38. struct Foo<A, Goo>
  39. {
  40.   // ...
  41. };
  42.        
  43. template <typename A, template <typename> class B>
  44. void Foo<A,B>::foo1() { cout << "foo1" << endl;}