fork(6) download
  1. #include <iostream>
  2.  
  3. template <class T, typename U = void> class A;
  4.  
  5. template <class T>
  6. class C
  7. {
  8. public:
  9. typedef T Var_t;
  10. };
  11.  
  12. template <class T>
  13. class B : public C<T>
  14. {
  15. };
  16.  
  17. template <class T>
  18. class A<B<T>>
  19. {
  20. public:
  21. A() { std::cout << "Here." << std::endl; }
  22. };
  23.  
  24. template <class T>
  25. class A<T, typename std::enable_if<
  26. std::is_base_of<C<typename T::Var_t>, T>::value>
  27. //true>
  28. ::type>
  29. {
  30. public:
  31. A() { std::cout << "There." << std::endl;}
  32. };
  33.  
  34. int main()
  35. {
  36. A<B<int>> a;
  37. return 0;
  38. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:36:12: error: ambiguous template instantiation for ‘class A<B<int> >’
  A<B<int>> a;
            ^
prog.cpp:18:7: note: candidates are: template<class T> class A<B<T> > [with T = int]
 class A<B<T>>
       ^~~~~~~
prog.cpp:25:7: note:                 template<class T> class A<T, typename std::enable_if<std::is_base_of<C<typename T::Var_t>, T>::value>::type> [with T = B<int>]
 class A<T, typename std::enable_if<
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              std::is_base_of<C<typename T::Var_t>, T>::value>
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              //true>
                              ~~~~~~~
                              ::type>
                              ~~~~~~~
prog.cpp:36:12: error: aggregate ‘A<B<int> > a’ has incomplete type and cannot be defined
  A<B<int>> a;
            ^
stdout
Standard output is empty