function template in c++

l am trying to write a c++ function template which takes two parameter one a pointe to any array of type T and other integer, which l write a main program declaring 3 arrays element, first array is of integer, second is of double and third is character,then print the array.
below is the code l wrote on my own but it is not building, can someone help me figure out where l went wrong

//functemp.cpp--using a function template
#include <iostream>
//function template prototype
template <class T>

int main()

{
using namespace std;

int i =10;
int j=10

cout <<"i,j = "<< i <<", << j <<". \n"
cout <<; \n".
print (i,j);//void print (int &, int &)
cout << "now, j=<< i <<". "<<j<<". \n";
double x=10
double y=20
cout << "x,y=" << x <<", "<< y <<". \n".
cout <<: \n".
print (x,y); //voidprint (double &, double &)
cout << "now x,y =" << x<<", "<< y <<". \n".
//cin.set();

return 0;

}
Where is the function print() that you're supposed to write a template for?

Be sure to read this:
http://cplusplus.com/doc/tutorial/templates/

Come back and ask again if you don't understand.
Last edited on
EVERY LINE had an error on it. I've highlighted those for you. Fix those first before even attempting template functions. Things like using decimals instead of semi-colons are completely obvious and you should have been able to find those yourself without coming to the forums if you had spent 2 minutes to review your code. The mis-matched quotes should also be obvious as any text editor (other than notepad) will highlight strings for you and you should have noticed the colored text in the wrong spot. You had template<class T>, but no function header to go with it!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//functemp.cpp--using a function template
#include <iostream>
//function template prototype
//template <class T> // You didn't finish the template function prototype.

int main()
{
  using namespace std;
  
  int i =10;
  int j =10;                                   // missing a ;
  
  cout <<"i,j = "<< i <<", "<< j <<". \n";     // missing a " and a ; in this line
  cout << "\n";                                // ; was in the wrong spot, missing a "
  //print (i,j);                               // Function undefined
  cout << "now, j="<< i <<". "<<j<<". \n";     // missing a "
  double x=10;                                 // missing a ;
  double y=20;                                 // missing a ;
  cout << "x,y=" << x <<", "<< y <<". \n";     // used a . instead of ;
  cout <<" \n";                                // used a : instead of " and . instead of ;
  //print (x,y);                               // function was not defined!
  cout << "now x,y =" << x<<", "<< y <<". \n"; // used a . instead of ;
  //cin.set();
  
  return 0;
}                                              // missing } 
Last edited on
Topic archived. No new replies allowed.