fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4. #include <string>
  5. #include <sstream>
  6. #include <iterator>
  7. using namespace std;
  8.  
  9.  
  10. template <typename Foo>
  11. struct Gizmo
  12. {
  13. Foo mF;
  14. Gizmo (Foo f) : mF (f) {};
  15.  
  16. template <template <typename> class Cont> void DoIt(
  17. typename Cont <string>::iterator begin,
  18. typename Cont <string>::iterator end)
  19. const
  20. {
  21. stringstream ss;
  22. ss << "(" << this->mF << ")\n";
  23. const std::string s = ss.str();
  24. copy (begin, end, ostream_iterator <std::string> (cout, s.c_str()));
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. list <string> l;
  31. l.push_back ("Hello");
  32. l.push_back ("world");
  33.  
  34. Gizmo <unsigned> g (42);
  35. g.DoIt (l.begin(), l.end());
  36. }
Compilation error #stdin compilation error #stdout 0s 3468KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:35:28: error: no matching function for call to ‘Gizmo<unsigned int>::DoIt(std::list<std::basic_string<char> >::iterator, std::list<std::basic_string<char> >::iterator)’
  g.DoIt (l.begin(), l.end());
                            ^
prog.cpp:35:28: note: candidate is:
prog.cpp:16:49: note: template<template<class> class typedef Cont Cont> void Gizmo<Foo>::DoIt(typename Cont<std::basic_string<char> >::iterator, typename Cont<std::basic_string<char> >::iterator) const [with Cont = Cont; Foo = unsigned int]
  template <template <typename> class Cont> void DoIt(
                                                 ^
prog.cpp:16:49: note:   template argument deduction/substitution failed:
prog.cpp:35:28: note:   couldn't deduce template parameter ‘template<class> class typedef Cont Cont’
  g.DoIt (l.begin(), l.end());
                            ^
stdout
Standard output is empty