Thread: RE: [Dev-C++] Templates - course examples don't work!
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-04-02 12:06:11
|
<html><div style='background-color:'><DIV>
<P>Oh this is wonderful news *sarcasm* So the code is ok but the compiler won't work? What can I do?</P>
<P>It seems silly to revert back to DEV-C++ because my expensive microsoft compiler doesn't compile properly.</P>
<P>Suggestions?<BR><BR></P></DIV>
<DIV></DIV>
<DIV></DIV>>From: "Ioannis Vranos" <NO...@HO...>
<DIV></DIV>>To: "Dev-C++" <DEV...@LI...>
<DIV></DIV>>Subject: RE: [Dev-C++] Templates - course examples don't work!
<DIV></DIV>>Date: Tue, 2 Apr 2002 14:39:54 +0200
<DIV></DIV>>
<DIV></DIV>>Do not use VC++ 6 to learn C++. It doesn't support the ANSI C++
<DIV></DIV>>standard and was mentioned as "the broken compiler". Of course it is
<DIV></DIV>>since it was created at the time of Windows 95! With VC++ 7 things are a
<DIV></DIV>>lot better of course.
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>The only error that i found in your code is that you had forgotten some
<DIV></DIV>>quotes. Also iostream.h can be considered an error.
<DIV></DIV>>
<DIV></DIV>>Your code in better shape:
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>// This is a program to interchange two values by using function
<DIV></DIV>>templates.
<DIV></DIV>>
<DIV></DIV>>#include <IOSTREAM>
<DIV></DIV>>
<DIV></DIV>>template<TYPENAME X>
<DIV></DIV>>X Temp1(X &, X &);
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>int main()
<DIV></DIV>>{
<DIV></DIV>>
<DIV></DIV>>int Var;
<DIV></DIV>>
<DIV></DIV>>int Var1 = 20;
<DIV></DIV>>
<DIV></DIV>>int Var2 = 25;
<DIV></DIV>>
<DIV></DIV>>cout << "The value in Var1 = " << Var1 << endl;
<DIV></DIV>>
<DIV></DIV>>cout << "The value in Var2 = " << Var2 << endl;
<DIV></DIV>>
<DIV></DIV>>Var = Temp1(Var1, Var2);
<DIV></DIV>>
<DIV></DIV>>cout << "The sum is: "<< Var << endl;
<DIV></DIV>>
<DIV></DIV>>return 0;
<DIV></DIV>>}
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>template<TYPENAME X>
<DIV></DIV>>X Temp1(X &A, X &B)
<DIV></DIV>>
<DIV></DIV>>{
<DIV></DIV>>
<DIV></DIV>>X Var;
<DIV></DIV>>
<DIV></DIV>>Var = A + B;
<DIV></DIV>>
<DIV></DIV>>return Var;
<DIV></DIV>>
<DIV></DIV>>}
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>Ioannis
<DIV></DIV>>
<DIV></DIV>>* Ioannis Vranos
<DIV></DIV>>* Programming pages: http://www.noicys.cjb.net
<DIV></DIV>><HTTP: www.noicys.cjb.net />
<DIV></DIV>>* Alternative URL: http://run.to/noicys
<DIV></DIV>>
<DIV></DIV>>-----Original Message-----
<DIV></DIV>>From: dev...@li...
<DIV></DIV>>[mailto:dev...@li...] On Behalf Of Daniel
<DIV></DIV>>Glenfield
<DIV></DIV>>Sent: Tuesday, April 02, 2002 12:43 PM
<DIV></DIV>>To: dev...@li...
<DIV></DIV>>Subject: [Dev-C++] Templates - course examples don't work!
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>I'm using VC++ and the examples from my course will not compile and I
<DIV></DIV>>know not why! It tells me A and B are not declared, but I think they
<DIV></DIV>>are! Help me out will you?
<DIV></DIV>>
<DIV></DIV>>// This is a program to interchange two values by using function
<DIV></DIV>>templates.
<DIV></DIV>>
<DIV></DIV>>#include <IOSTREAM.H>
<DIV></DIV>>
<DIV></DIV>>template<TYPENAME X>
<DIV></DIV>>
<DIV></DIV>>int Temp1(X &, X &);
<DIV></DIV>>
<DIV></DIV>>int main()
<DIV></DIV>>
<DIV></DIV>>{
<DIV></DIV>>
<DIV></DIV>>int Var;
<DIV></DIV>>
<DIV></DIV>>int Var1 = 20;
<DIV></DIV>>
<DIV></DIV>>int Var2 = 25;
<DIV></DIV>>
<DIV></DIV>>cout << "The value in Var1 = " << Var1 << endl;
<DIV></DIV>>
<DIV></DIV>>cout << "The value in Var2 = " << Var2 << endl;
<DIV></DIV>>
<DIV></DIV>>Var = Temp1(Var1, Var2);
<DIV></DIV>>
<DIV></DIV>>cout << "The sum is: << Var << endl;
<DIV></DIV>>
<DIV></DIV>>return 0;
<DIV></DIV>>
<DIV></DIV>>}
<DIV></DIV>>
<DIV></DIV>>template<TYPENAME X>
<DIV></DIV>>
<DIV></DIV>>int Temp1(X &A, X &B)
<DIV></DIV>>
<DIV></DIV>>{
<DIV></DIV>>
<DIV></DIV>>X Var;
<DIV></DIV>>
<DIV></DIV>>Var = A + B;
<DIV></DIV>>
<DIV></DIV>>return Var;
<DIV></DIV>>
<DIV></DIV>>}
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>> _____
<DIV></DIV>>
<DIV></DIV>>Send and receive Hotmail on your mobile device: Click
<DIV></DIV>><HTTP: 13 g.msn.com 1HM305301> Here
<DIV></DIV>>_______________________________________________ Dev-cpp-users mailing
<DIV></DIV>>list Dev...@li...
<DIV></DIV>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
<DIV></DIV>>
<DIV></DIV></div><br clear=all><hr>Chat with friends online, try MSN Messenger: <a href='http://g.msn.com/1HM305301/11'>Click Here</a><br></html>
|
|
From: Ioannis V. <no...@ho...> - 2002-04-02 19:10:28
|
Sometime ago there was someone from the list who asked (me or all, i can't recall) what compiler to buy and i had recommended him either Borland C++ Builder or to wait for the upcoming Visual C++ 7 .NET. But he didn't listen to me and he would buy the 5 years old(!) VC++ 6. I do not remember the person but if he was you well... Whether you are him or not, well there are 2 options: There is VC++ 7 Upgrade package (but the IDE of 7 sucks) and there is the *extremelly good* Intel C++ 5 compiler which works under the VC++ IDE and it is highly standard compliant and it has *crazy* speed/space optimizations. Very high state of the art. I haven't seen it personally but i have heared very good words from good programmers. Anyway the options can be summarized: Intel C++ 5 for VC++, Borland C++ Builder 6 and Visual C++ 7 Upgrade. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys -----Original Message----- From: Daniel Glenfield [mailto:sp...@ho...] Sent: Tuesday, April 02, 2002 2:06 PM To: no...@ho...; dev...@li... Subject: RE: [Dev-C++] Templates - course examples don't work! Oh this is wonderful news *sarcasm* So the code is ok but the compiler won't work? What can I do? It seems silly to revert back to DEV-C++ because my expensive microsoft compiler doesn't compile properly. Suggestions? |
|
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;
}
|