RE: [Dev-C++] Templates - course examples don't work!
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ho...> - 2002-04-02 11:40:39
|
Do not use VC++ 6 to learn C++. It doesn't support the ANSI C++
standard and was mentioned as "the broken compiler". Of course it is
since it was created at the time of Windows 95! With VC++ 7 things are a
lot better of course.
The only error that i found in your code is that you had forgotten some
quotes. Also iostream.h can be considered an error.
Your code in better shape:
// This is a program to interchange two values by using function
templates.
#include <iostream>
template<typename X>
X Temp1(X &, X &);
int main()
{
int Var;
int Var1 = 20;
int Var2 = 25;
cout << "The value in Var1 = " << Var1 << endl;
cout << "The value in Var2 = " << Var2 << endl;
Var = Temp1(Var1, Var2);
cout << "The sum is: "<< Var << endl;
return 0;
}
template<typename X>
X Temp1(X &A, X &B)
{
X Var;
Var = A + B;
return Var;
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>
* Alternative URL: http://run.to/noicys
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Daniel
Glenfield
Sent: Tuesday, April 02, 2002 12:43 PM
To: dev...@li...
Subject: [Dev-C++] Templates - course examples don't work!
I'm using VC++ and the examples from my course will not compile and I
know not why! It tells me A and B are not declared, but I think they
are! Help me out will you?
// This is a program to interchange two values by using function
templates.
#include <iostream.h>
template<typename X>
int Temp1(X &, X &);
int main()
{
int Var;
int Var1 = 20;
int Var2 = 25;
cout << "The value in Var1 = " << Var1 << endl;
cout << "The value in Var2 = " << Var2 << endl;
Var = Temp1(Var1, Var2);
cout << "The sum is: << Var << endl;
return 0;
}
template<typename X>
int Temp1(X &A, X &B)
{
X Var;
Var = A + B;
return Var;
}
_____
Send and receive Hotmail on your mobile device: Click
<http://g.msn.com/1HM305301/13> Here
_______________________________________________ Dev-cpp-users mailing
list Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|