Re: [Dev-C++] Dev-cpp-users Digest, Vol 25, Issue 1
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alexsandro M. <ale...@ho...> - 2008-06-03 15:57:27
|
Thank you all for helping me out. > From: dev...@li...> Subject: Dev-cpp-users Digest, Vol 25, Issue 1> To: dev...@li...> Date: Tue, 3 Jun 2008 01:33:27 -0700> > Send Dev-cpp-users mailing list submissions to> dev...@li...> > To subscribe or unsubscribe via the World Wide Web, visit> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> or, via email, send a message with subject or body 'help' to> dev...@li...> > You can reach the person managing the list at> dev...@li...> > When replying, please edit your Subject line so it is more specific> than "Re: Contents of Dev-cpp-users digest..."> > > Today's Topics:> > 1. Re: templates + linker error (Per Westermark)> 2. Re: templates + linker error (Jorge Guevara)> 3. Re: templates + linker error (Per Westermark)> 4. Choose a word from a .txt file (Alexsandro Meireles)> 5. Re: Choose a word from a .txt file (Lloyd)> 6. Re: Choose a word from a .txt file (Per Westermark)> 7. Re: Choose a word from a .txt file (Per Westermark)> > > ----------------------------------------------------------------------> > Message: 1> Date: Mon, 26 May 2008 20:12:24 +0200 (CEST)> From: Per Westermark <pw...@ia...>> Subject: Re: [Dev-C++] templates + linker error> To: Lloyd <ll...@cd...>> Cc: dev...@li...> Message-ID:> <Pin...@ia...>> Content-Type: TEXT/PLAIN; charset=US-ASCII> > Think a bit about it.> > What code to you suggest that the compiler should enerate when it compiles> calc.cpp? If the compiler does not know that other source files will use> the template parameter "double", how will the compiler then be able to add> a "double" version of multiply when it compiles calc.cpp?> > Remember that it is the compiler, not the linker, that produces the> runnable code. The linker will have no use for an object file that doesn't> contain instantiated template functions.> > /pwm> > On Mon, 26 May 2008, Lloyd wrote:> > > The reason for the error is you are not passing the obj file of calc.cpp> > to the linker. Make appropriate settings in DevCpp. I think, you have to> > add calc.cpp to your project. Sorry I dont use DevCpp.> >> >> > On Sun, 2008-05-25 at 16:42 -0500, Jorge Guevara wrote:> > >> > > i have 3 source calc.h calc.cpp and principal.cpp (i compilated it> > > with devcpp)> > >> > > i have this error:> > > In function `main':> > > [Linker error] undefined reference to `calc<double>::multiply(double,> > > double)'> > > ld returned 1 exit status> > > [Build Error] ["Proyecto] Error 1> > >> > > somebody could help me please :)> > >> > > /********calc.h******/> > > #ifndef _CALC_H> > > #define _CALC_H> > >> > > template <class A_Type> class calc> > > {> > > public:> > > A_Type multiply(A_Type x, A_Type y);> > > A_Type add(A_Type x, A_Type y);> > >> > > };> > >> > > #endif> > >> > > /****calc.cpp******/> > > #include "calc.h"> > > #include <iostream>> > > using namespace std;> > >> > > template <class A_Type> A_Type calc<A_Type>::multiply(A_Type x,A_Type> > > y)> > > {> > > return x*y;> > > }> > > template <class A_Type> A_Type calc<A_Type>::add(A_Type x, A_Type y)> > > {> > > return x+y;> > > }> > >> > >> > > /******principal.cpp*****/> > > #include "calc.h"> > > #include <iostream>> > > #include <cstdlib>> > >> > > using namespace std;> > >> > > int main()> > > {> > > calc <double> a_calc_class;> > > double a, b;> > > a=4.3;> > > b=3.4;> > > a_calc_class.multiply(a,b);> > >> > > system("PAUSE");> > > return EXIT_SUCCESS;> > > }> > > /***************************/> > >> > >> > > -------------------------------------------------------------------------> > > This SF.net email is sponsored by: Microsoft> > > Defy all challenges. Microsoft(R) Visual Studio 2008.> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/> > > _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> >> >> > ______________________________________> > Scanned and protected by Email scanner> >> > -------------------------------------------------------------------------> > This SF.net email is sponsored by: Microsoft> > Defy all challenges. Microsoft(R) Visual Studio 2008.> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/> > _______________________________________________> > Dev-cpp-users mailing list> > Dev...@li...> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> >> > > > > ------------------------------> > Message: 2> Date: Tue, 27 May 2008 15:17:27 -0500> From: "Jorge Guevara" <jor...@gm...>> Subject: Re: [Dev-C++] templates + linker error> To: "Per Westermark" <pw...@ia...>> Cc: dev...@li...> Message-ID:> <51a...@ma...>> Content-Type: text/plain; charset="iso-8859-1"> > I try with this. and no problem> > #include <iostream>> #include <cstdlib>> #include "mypair.hpp"> #include "mypair.cpp" // i include the implementation in the source> principal.cpp> > the question is less efficient?, or its ok?> > bytes> > > 2008/5/26, Per Westermark <pw...@ia...>:> >> > The compiler can't create the code for a template function unless it sees> > the implementation when you try to use the template function.> >> > You should have the implementation of your multiply function in the header> > file, and not hidden in a cpp file.> >> > It is only the linker that will see the generated code from multiple cpp> > files, and neither the compiler nor the compiler knows that calc.cpp> > should create a specific version of the multiply function with the double> > data type.> >> > /pwm> >> >> > On Sun, 25 May 2008, Jorge Guevara wrote:> >> > > i have 3 source calc.h calc.cpp and principal.cpp (i compilated it with> > > devcpp)> > >> > > i have this error:> > > In function `main':> > > [Linker error] undefined reference to `calc<double>::multiply(double,> > > double)'> > > ld returned 1 exit status> > > [Build Error] ["Proyecto] Error 1> > >> > > somebody could help me please :)> > >> > > /********calc.h******/> > > #ifndef _CALC_H> > > #define _CALC_H> > >> > > template <class A_Type> class calc> > > {> > > public:> > > A_Type multiply(A_Type x, A_Type y);> > > A_Type add(A_Type x, A_Type y);> > >> > > };> > >> > > #endif> > >> > > /****calc.cpp******/> > > #include "calc.h"> > > #include <iostream>> > > using namespace std;> > >> > > template <class A_Type> A_Type calc<A_Type>::multiply(A_Type x,A_Type y)> > > {> > > return x*y;> > > }> > > template <class A_Type> A_Type calc<A_Type>::add(A_Type x, A_Type y)> > > {> > > return x+y;> > > }> > >> > >> > > /******principal.cpp*****/> > > #include "calc.h"> > > #include <iostream>> > > #include <cstdlib>> > >> > > using namespace std;> > >> > > int main()> > > {> > > calc <double> a_calc_class;> > > double a, b;> > > a=4.3;> > > b=3.4;> > > a_calc_class.multiply(a,b);> > >> > > system("PAUSE");> > > return EXIT_SUCCESS;> > > }> > > /***************************/> > >> >> >> > > -- > Ing. Jorge Luis Guevara Diaz> Bs Ciencias de la Computacion> Maestrante en Ciencia de la Computaci?n> http://jorge.sistemasyservidores.com http://inf.unitru.edu.pe/~jlgd> Escuela de Inform?tica - Universidad Nacional de Trujillo> Escuela de Ingenier?a de Sistemas - Universidad Privada del Norte> -------------- next part --------------> An HTML attachment was scrubbed...> > ------------------------------> > Message: 3> Date: Wed, 28 May 2008 06:36:29 +0200 (CEST)> From: Per Westermark <pw...@ia...>> Subject: Re: [Dev-C++] templates + linker error> To: Jorge Guevara <jor...@gm...>> Cc: dev...@li...> Message-ID:> <Pin...@ia...>> Content-Type: TEXT/PLAIN; charset=ISO-8859-1> > Always avoid including cpp files. cpp files are indented to generate> object files and be linked.> > Templated functions are intended to be compiled into object files first> when needed. As I wrote in one of my earlier mails, template functions> should be placed in the relevant header file.> > Look at the STL files: In all cases, the actual source code> for the implementations of lists, trees, arrays etc are available in the> header files.> > /pwm> > On Tue, 27 May 2008, Jorge Guevara wrote:> > > I try with this. and no problem> >> > #include <iostream>> > #include <cstdlib>> > #include "mypair.hpp"> > #include "mypair.cpp" // i include the implementation in the source> > principal.cpp> >> > the question is less efficient?, or its ok?> >> > bytes> >> >> > 2008/5/26, Per Westermark <pw...@ia...>:> > >> > > The compiler can't create the code for a template function unless it sees> > > the implementation when you try to use the template function.> > >> > > You should have the implementation of your multiply function in the header> > > file, and not hidden in a cpp file.> > >> > > It is only the linker that will see the generated code from multiple cpp> > > files, and neither the compiler nor the compiler knows that calc.cpp> > > should create a specific version of the multiply function with the double> > > data type.> > >> > > /pwm> > >> > >> > > On Sun, 25 May 2008, Jorge Guevara wrote:> > >> > > > i have 3 source calc.h calc.cpp and principal.cpp (i compilated it with> > > > devcpp)> > > >> > > > i have this error:> > > > In function `main':> > > > [Linker error] undefined reference to `calc<double>::multiply(double,> > > > double)'> > > > ld returned 1 exit status> > > > [Build Error] ["Proyecto] Error 1> > > >> > > > somebody could help me please :)> > > >> > > > /********calc.h******/> > > > #ifndef _CALC_H> > > > #define _CALC_H> > > >> > > > template <class A_Type> class calc> > > > {> > > > public:> > > > A_Type multiply(A_Type x, A_Type y);> > > > A_Type add(A_Type x, A_Type y);> > > >> > > > };> > > >> > > > #endif> > > >> > > > /****calc.cpp******/> > > > #include "calc.h"> > > > #include <iostream>> > > > using namespace std;> > > >> > > > template <class A_Type> A_Type calc<A_Type>::multiply(A_Type x,A_Type y)> > > > {> > > > return x*y;> > > > }> > > > template <class A_Type> A_Type calc<A_Type>::add(A_Type x, A_Type y)> > > > {> > > > return x+y;> > > > }> > > >> > > >> > > > /******principal.cpp*****/> > > > #include "calc.h"> > > > #include <iostream>> > > > #include <cstdlib>> > > >> > > > using namespace std;> > > >> > > > int main()> > > > {> > > > calc <double> a_calc_class;> > > > double a, b;> > > > a=4.3;> > > > b=3.4;> > > > a_calc_class.multiply(a,b);> > > >> > > > system("PAUSE");> > > > return EXIT_SUCCESS;> > > > }> > > > /***************************/> > > >> > >> > >> >> >> > --> > Ing. Jorge Luis Guevara Diaz> > Bs Ciencias de la Computacion> > Maestrante en Ciencia de la Computaci?n> > http://jorge.sistemasyservidores.com http://inf.unitru.edu.pe/~jlgd> > Escuela de Inform?tica - Universidad Nacional de Trujillo> > Escuela de Ingenier?a de Sistemas - Universidad Privada del Norte> >> > > > > ------------------------------> > Message: 4> Date: Tue, 3 Jun 2008 01:24:13 -0300> From: Alexsandro Meireles <ale...@ho...>> Subject: [Dev-C++] Choose a word from a .txt file> To: <dev...@li...>> Message-ID: <BAY...@ph...>> Content-Type: text/plain; charset="iso-8859-1"> > Dear users,> > How can I write a script to look a word in a .txt file with two columns (one is the word and the other is the answer I need) and give an answer which is in the second column. In other words, a user types a word, then the script match it with a word in a .txt file (first column) and gives the answer (second column).> > Thanks in advance!> > Alex.> _________________________________________________________________> Cansado de espa?o para s? 50 fotos? Conhe?a o Spaces, o site de relacionamentos com at? 6,000 fotos!> http://www.amigosdomessenger.com.br> -------------- next part --------------> An HTML attachment was scrubbed...> > ------------------------------> > Message: 5> Date: Tue, 03 Jun 2008 10:19:31 +0530> From: Lloyd <ll...@cd...>> Subject: Re: [Dev-C++] Choose a word from a .txt file> To: Alexsandro Meireles <ale...@ho...>> Cc: dev...@li...> Message-ID: <1212468571.3808.1.camel@RCCF025>> Content-Type: text/plain> > Wouldn't regular expression search help you? May be better solution> could be there...> > check for regex in www.boost.org> > > On Tue, 2008-06-03 at 01:24 -0300, Alexsandro Meireles wrote:> > Dear users,> > > > How can I write a script to look a word in a .txt file with two> > columns (one is the word and the other is the answer I need) and give> > an answer which is in the second column. In other words, a user types> > a word, then the script match it with a word in a .txt file (first> > column) and gives the answer (second column).> > > > Thanks in advance!> > > > Alex.> > > > > > ______________________________________> Scanned and protected by Email scanner> > > > ------------------------------> > Message: 6> Date: Tue, 3 Jun 2008 10:31:54 +0200 (CEST)> From: Per Westermark <pw...@ia...>> Subject: Re: [Dev-C++] Choose a word from a .txt file> To: Alexsandro Meireles <ale...@ho...>> Cc: dev...@li...> Message-ID:> <Pin...@ia...>> Content-Type: TEXT/PLAIN; charset=ISO-8859-1> > Why do you talk about scrit? This is the Dev-C++ list, where people> normally uses Dev-C++ to write C or C++ applications. The traditional use> of the word 'script' is for some interpretative programming - often in a> batch file or similar.> > Anyway - is the file sorted? Does it contain a huge number of words?> > If no to any of the above two questions: Open file. Read one line into a> buffer (for example with fgets()). Find the first separator character> (space, tab or whatever the file is using). Replace the separator with a> '\0'; Compare start of line with the word you want to match. If no match,> load next line and repeat. If match, step past the separator and then eath> any more separator characters. Locate the '\n' at end of the read line,> and replace with a '\0'; Emit the extracted answer.> > If the file is huge and sorted, get the file size. Move to the middle of> the file. Read one (possibly partial line). Read the next line. Extract> the word and see if you are above/below the requested language. If you> found the word - extract answer. If word too large, move back to one> quarter of the file and repat. If word was too small, seek to 75% of file> and repeat. All the time remember the <min,max> range that the> expected word must be in. Note that <min> and <max> should represent the> start position of text lines, (or the end-of-file) so when you> specify <min> as seek offset, you do not have to thow away any> potentially partial text lines - you know that it is a full line> and can check that word immediately.> > /pwm> > On Tue, 3 Jun 2008, Alexsandro Meireles wrote:> > > Dear users,> >> > How can I write a script to look a word in a .txt file with two columns (one is the word and the other is the answer I need) and give an answer which is in the second column. In other words, a user types a word, then the script match it with a word in a .txt file (first column) and gives the answer (second column).> >> > Thanks in advance!> >> > Alex.> > _________________________________________________________________> > Cansado de espa?o para s? 50 fotos? Conhe?a o Spaces, o site de relacionamentos com at? 6,000 fotos!> > http://www.amigosdomessenger.com.br> > > > > ------------------------------> > Message: 7> Date: Tue, 3 Jun 2008 10:33:12 +0200 (CEST)> From: Per Westermark <pw...@ia...>> Subject: Re: [Dev-C++] Choose a word from a .txt file> To: Lloyd <ll...@cd...>> Cc: Alexsandro Meireles <ale...@ho...>,> dev...@li...> Message-ID:> <Pin...@ia...>> Content-Type: TEXT/PLAIN; charset=US-ASCII> > No regular expressions if he is looking for an exact match. Regular> expressions are there to look for patterns. Normal strcmp()/strncmp() is> faster when looking for exact matches.> > /pwm> > On Tue, 3 Jun 2008, Lloyd wrote:> > > Wouldn't regular expression search help you? May be better solution> > could be there...> >> > check for regex in www.boost.org> >> >> > On Tue, 2008-06-03 at 01:24 -0300, Alexsandro Meireles wrote:> > > Dear users,> > >> > > How can I write a script to look a word in a .txt file with two> > > columns (one is the word and the other is the answer I need) and give> > > an answer which is in the second column. In other words, a user types> > > a word, then the script match it with a word in a .txt file (first> > > column) and gives the answer (second column).> > >> > > Thanks in advance!> > >> > > Alex.> > >> >> >> >> > ______________________________________> > Scanned and protected by Email scanner> >> > -------------------------------------------------------------------------> > This SF.net email is sponsored by: Microsoft> > Defy all challenges. Microsoft(R) Visual Studio 2008.> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/> > _______________________________________________> > Dev-cpp-users mailing list> > Dev...@li...> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> >> > > > > ------------------------------> > -------------------------------------------------------------------------> This SF.net email is sponsored by: Microsoft> Defy all challenges. Microsoft(R) Visual Studio 2008.> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/> > ------------------------------> > _______________________________________________> Dev-cpp-users mailing list> Dev...@li...> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> > > End of Dev-cpp-users Digest, Vol 25, Issue 1> ******************************************** _________________________________________________________________ Receba GRÁTIS as mensagens do Messenger no seu celular quando você estiver offline. Conheça o MSN Mobile! http://mobile.live.com/signup/signup2.aspx?lc=pt-br |