Re: [fpc-pascal] Interesting namespace question
- Original Message - From: ik [EMAIL PROTECTED] Date: Thursday, June 21, 2007 2:53 pm Subject: [fpc-pascal] Interesting namespace question Hi, I saw an interesting bug on C++, and I was wondering how to solve this type of bug in Pascal: {$MODE OBJFPC} program namespace_test; function test : boolean; begin result := true; end; type TTest = class function test : boolean; end; function TTest.test : boolean; begin result := test; end; var c_test : TTest; begin c_test := TTest.create; try writeln (c_test.test); finally c_test.free; end; end. OK the question is, the TTest.test, what is the test function that it will call, the one inside the class, or the one outside it (I belive that it will call itself once), and how can i call the function outside the class ? I think it will call itself, until it runs out of stack space (error 202). If you want to call the test function, use namespace_test.test; Vincent P.S. To be sure, just compile the code ... ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interesting namespace question
Op Thu, 21 Jun 2007, schreef [EMAIL PROTECTED]: I think it will call itself, until it runs out of stack space (error 202). No, it won't, test here refers to the function result variable. Daniël___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interesting namespace question
Hi! New list member here... I saw an interesting bug on C++, and I was wondering how to solve this type of bug in Pascal: This is easily resolved. Try this version: {$MODE OBJFPC} program namespace_test; function test : boolean; begin writeln('public function test called.'); result := true; end; type TTest = class function test : boolean; end; function TTest.test : boolean; begin writeln('method TTest.test called.'); result := test; end; var c_test : TTest; begin c_test := TTest.create; try writeln (c_test.test); // calls the class method writeln (namespace_test.test); // calls the public function finally c_test.free; end; end. Tom ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interesting namespace question
Hi, Thank you all for the answer. I learned that i can do program_name. for namespace as well cool :) Ido On 6/21/07, Tom York [EMAIL PROTECTED] wrote: Hi! New list member here... I saw an interesting bug on C++, and I was wondering how to solve this type of bug in Pascal: This is easily resolved. Try this version: {$MODE OBJFPC} program namespace_test; function test : boolean; begin writeln('public function test called.'); result := true; end; type TTest = class function test : boolean; end; function TTest.test : boolean; begin writeln('method TTest.test called.'); result := test; end; var c_test : TTest; begin c_test := TTest.create; try writeln (c_test.test); // calls the class method writeln (namespace_test.test); // calls the public function finally c_test.free; end; end. Tom ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal -- http://ik.homelinux.org/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal