fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <vector>
  4.  
  5.  
  6. class ThingBase {
  7. public:
  8. virtual void printHi() = 0;
  9.  
  10. };
  11.  
  12. class Thing : public ThingBase
  13. {
  14. void printHi(){
  15. std::cout << "hi\n";
  16. }
  17. };
  18.  
  19.  
  20. template<typename ThingType>
  21. class Container{
  22. private:
  23. std::vector<ThingType> m_things;
  24. public:
  25.  
  26. typename std::enable_if<std::is_base_of<ThingBase, ThingType>::value>::type p()
  27. {
  28. m_things[0].printHi();
  29. };
  30. };
  31.  
  32.  
  33. int main() {
  34.  
  35. //Container<Thing> stuff; // works!
  36. Container<int> stuff; // doesn't work :(
  37.  
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 4900KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘class Container<int>’:
prog.cpp:36:17:   required from here
prog.cpp:26:78: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
  typename std::enable_if<std::is_base_of<ThingBase, ThingType>::value>::type p()
                                                                              ^
stdout
Standard output is empty