Код: Выделить всё
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template <typename type>
type max (type a, type b) {
return (a > b) ? a : b;
}
int main () {
int a = 11, b = 24;
double c = 3.1, d = 3.0;
string e = "ня", f = "ам";
cout << "a " << a << " b " << b << " max " << max(a, b) << endl;
cout << "c " << c << " d " << d << " max " << max(c, d) << endl;
cout << "e " << e << " f " << f << " max " << max(e, f) << endl;
return 0;
}ругается так:
Код: Выделить всё
navi ~ $ g++ tes.cpp
tes.cpp: In function ‘int main()’:
tes.cpp:18: ошибка: вызов перегруженной функции ‘max(int&, int&)’ неоднозначен
tes.cpp:8: замечание: претенденты: type max(type, type) [with type = int]
/usr/lib/gcc/i486-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_algobase.h:206: замечание: const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = int]
tes.cpp:19: ошибка: вызов перегруженной функции ‘max(double&, double&)’ неоднозначен
tes.cpp:8: замечание: претенденты: type max(type, type) [with type = double]
/usr/lib/gcc/i486-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_algobase.h:206: замечание: const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = double]
tes.cpp:20: ошибка: вызов перегруженной функции ‘max(std::string&, std::string&)’ неоднозначен
tes.cpp:8: замечание: претенденты: type max(type, type) [with type = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
/usr/lib/gcc/i486-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_algobase.h:206: замечание: const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = std::string]Посмотрел ответы к упражнениям, там практически тоже самое, только функция inline и Type вместо type
Где я напортачил?