Edit: Thank you for your answers! Like I said, this is code provided for a class, so the namespace and name of the function were included. I'm glad to understand what exactly namespace std entails though, and I've included your inputs as comments within my answer (though my answer remains unchanged).
The code below includes the piece I created. This is for a class, so this is the only part that I need judged. My compiler isn't running it (ambiguous calls to overloaded function) but I feel like this is correct.
template <class data_type>
void swap(data_type &a, data_type &b) //swaps 2 variables
{
data_type c; //temp variable
c = a;
a = b;
b = c;
}
Here is the full code:
#include <iostream>
#include <string>
using namespace std;
template <class data_type>
void swap(data_type &a, data_type &b) //swaps variables
{
data_type c;
c = a;
a = b;
b = c;
}
int main( )
{
string x = "first", y = "second";
int m = 10, n = 20;
char q = 'Q', r = 'R';
cout<<"x before swap called = "<<x<<" and y before swap called = "
<<y<<endl;
swap(x,y);
cout<<"x after swap called = "<<x<<" and y after swap called = "
<<y<<endl<<endl;
cout<<"m before swap called = "<<m<<" and n before swap called = "
<<n<<endl;
swap(m,n);
cout<<"m after swap called = "<<m<<" and n after swap called = "
<<n<<endl<<endl;
cout<<"q before swap called = "<<q<<" and r before swap called = "
<<r<<endl;
swap(q,r);
cout<<"q after swap called = "<<q<<" and r after swap called = "
<<r<<endl<<endl;
return 0;
}