Re: [Dev-C++] Templates - course examples don't work!
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel W. <d_w...@ho...> - 2002-04-03 04:50:56
|
Hi!!
The code is like is below, but it doesnt interchange any values, only =
print a sum
What Ioannis says is truth it "should" work under the ANSI standard. The =
corrections he made are for that standard, for this code to work in =
Visual C++ 6 you should correct only one line (and the quotes):
Bye
Daniel Wilches
dwi...@ma...
=20
// This is a program to interchange two values by using function =
templates.
#include <iostream.h>
template<typename X>
int Temp1(X& A, X& B); // This is the line you should change in =
VC++, in ANSI compilers you can write "int Temp1(X& , X& );"
int main()
{
int Var;
int Var1 =3D 20;
int Var2 =3D 25;
cout << "The value in Var1 =3D " << Var1 << endl;
cout << "The value in Var2 =3D " << Var2 << endl;
Var =3D Temp1(Var1, Var2);
cout << "The sum is:" << Var << endl;
return 0;
}
template<typename X>
int Temp1(X& A, X& B)
{
X Var;
Var =3D A + B;
return Var;
}
|