Kod: Zaznacz cały
#include "stdafx.h"
#include <iostream>
using namespace std;
template <class Type>
void swap(Type& firstVariable, Type& secondVariable)
{
Type temp;
temp = firstVariable;
firstVariable = secondVariable;
secondVariable = temp;
}
int main()
{
int a,b;
a=2;
b=3;
swap(a,b);
cout<<b;
cout<<a;
cout<<endl;
system("PAUSE");
return 0;
}
Nie rozumiem gdzie ta dwuznaczność, kod praktycznie przepisany z książki...1>------ Build started: Project: swapFile, Configuration: Debug Win32 ------
1> swapFile.cpp
1>swapFile.cpp(24): error C2668: 'swap' : ambiguous call to overloaded function
1> swapFile.cpp(9): could be 'void swap<int>(Type &,Type &)'
1> with
1> [
1> Type=int
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\utility(100): or 'void std::swap<std::ios_base::iostate>(_Ty &,_Ty &)'
1> with
1> [
1> _Ty=std::ios_base::iostate
1> ]
1> while trying to match the argument list '(int, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========