さて、ここにプログラムがあり、完全に正しく機能します
#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<<endl;
Swap(i,j);
cout<<"i, j = " << i <<" , " <<j<<endl;
}
template <typename T>
void Swap(T &a , T &b){
T temp;
temp = a ;
a = b;
b= temp;
}
しかし、関数の名前をSwapからswapに変更すると、次 のようなエラーが発生します。
エラー:オーバーロードされた'swap(int&、int&)'の呼び出しがあいまいです| 注:候補は次のとおりです。voidswap(T&、T&)[with T = int] | || ===ビルドが完了しました:1エラー、0警告=== |
テンプレートを使用して大文字で始まる関数を開始するのはどうしたのですか?