fork(3) download
  1. #include <iostream>
  2. template <typename T>
  3. int plus(T &a,T &b);
  4. int main()
  5. {
  6. using namespace std;
  7. int i=2;
  8. int j=4;
  9. cout<< "сумма "<<i<<" и "<<j<<"равна "<<plus(i,j);
  10. return 0;
  11. }
  12. template <typename T>
  13. int plus(T &a,T &b)
  14. {
  15. T temp;
  16. temp=a+b;
  17. return temp;
  18. }
  19.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:9:52: error: reference to 'plus' is ambiguous
 cout<< "сумма "<<i<<" и "<<j<<"равна "<<plus(i,j);
                                                    ^
prog.cpp:3:5: note: candidates are: template<class T> int plus(T&, T&)
 int plus(T &a,T &b);
     ^
In file included from /usr/include/c++/5/string:48:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/stl_function.h:147:12: note:                 template<class _Tp> struct std::plus
     struct plus;
            ^
stdout
Standard output is empty