little_greg Posted October 14, 2009 Report Share Posted October 14, 2009 всем доброго времени суток, подскажите, пож, почему при вызове функции происходит ошибка, "...call of overloaded `swap(int&, int&)' is ambiguous", (что-то вроде: вызов перегруженной функции двусмысленный) #include <iostream>using namespace std;template <typename T>void swap(T& a, T& b);int main(){int i = 10;int j = 20;cout << "i, j = " << i << ", " << j << ".\n";cout << "using int swap:\n";swap(i, j);cout << "now i, j = " << i << ", " << j << ".\n";double x = 24.5;double y = 81.7;cout << "x, y = " << x << ", " << y << ".\n";cout << "using double swap:\n";swap(x, y);cout << "now x, y = " << x << ", " << y << ".\n";system("pause");return 0;}template <typename T>void swap(T& a, T& b){ T temp; temp = a; a = b; b = a;} Quote Link to comment Share on other sites More sharing options...
Lion HC Posted October 14, 2009 Report Share Posted October 14, 2009 Для начала попробуйте: template <typename T>void swap(T& a, T& b){ T temp = a; a = b; b = temp;} Quote Link to comment Share on other sites More sharing options...
little_greg Posted October 14, 2009 Author Report Share Posted October 14, 2009 не сработало... Quote Link to comment Share on other sites More sharing options...
Тролль Posted October 14, 2009 Report Share Posted October 14, 2009 little_greg: Похоже, у тебя конфликт двух функций swap: определенной тобой и существовавшей раньше. Попробуй заменить имя функции swap на другое, скажем, swapm Quote Link to comment Share on other sites More sharing options...
little_greg Posted October 15, 2009 Author Report Share Posted October 15, 2009 и правда, заработало, спасибо Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.