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>
|