Alright so heres the program and works absolutely right
#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;
}
but when I change the function's name from Swap to swap
it generates an error saying
error: call of overloaded 'swap(int&, int&)' is ambiguous| note:
candidates are: void swap(T&, T&) [with T = int]| ||=== Build
finished: 1 errors, 0 warnings ===|
what happened is it a rule to start functions using templates to start with a capital letter ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…