From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86bb11cd9af49a58,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "R" Newsgroups: comp.lang.ada Subject: overloading operators with private variables Date: 29 Dec 2004 08:08:56 -0800 Organization: http://groups.google.com Message-ID: <1104336536.856474.279370@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 83.238.46.94 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104336540 8790 127.0.0.1 (29 Dec 2004 16:09:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 29 Dec 2004 16:09:00 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=83.238.46.94; posting-account=vW-V7A0AAADVHjc0FRFWzwhUHLUBcq4I Xref: g2news1.google.com comp.lang.ada:7294 Date: 2004-12-29T08:08:56-08:00 List-Id: Sorry to bother You again. But as a newbie... I've got new problem. I was trying to overload my test record. For example the multiplication. procedure Main is object : testclass.rec1; object2 : testclass.rec1; objectMul : testclass.rec1; begin testclass.Create(object, 100); testclass.Create(object2, 10); objectMul := object * object2; Put_Line(Integer'Image(testclass.Get(objectMul))); end Main; the "*" is(package testclass.adb): function "*"(left, right: rec1) return rec1 is tmp : Integer; ret: rec1; begin tmp := left.field * right.field; Create(ret, tmp); return ret; -- I'm not sure if Ada permits returning locally -- created objects, C++ don't permit it(well references yes)... end "*"; and the result of compilation is: main.adb:34:29: invalid operand types for operator "*" main.adb:34:29: left operand has private type "rec1" defined at testclass.ads:2 main.adb:34:29: right operand has private type "rec1" defined at testclass.ads:2 and the testclass.ads with rec1 and functions' prototypes: package testclass is type rec1 is tagged private; procedure Create(this: out rec1; s: in Integer); function Get(this: rec1) return Integer; function "*"(left, right: rec1) return rec1; private type rec1 is tagged record field: Integer; end record; end testclass; What should I do to overload these objects? Are there any mechanisms like C++ friends? Can my variable field still be private? and one thing about style ;-) When displaying Integer or Float is it better to use the Integer(Float)_Text_IO.Put or can I use Integer(Float)'Image with standard Put? -- best regards R -- Ada is quite easy but object progrmming in Ada is certainly not easy