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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ac93bb8de02c38a8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-08-25 06:49:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Overloading + operator Date: 25 Aug 2003 09:43:40 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <3F4981C5.BDF45D51@erols.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1061819138 11175 128.183.235.92 (25 Aug 2003 13:45:38 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 25 Aug 2003 13:45:38 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Xref: archiver1.google.com comp.lang.ada:41844 Date: 2003-08-25T13:45:38+00:00 List-Id: Daniel Allex writes: > I have some Ada code that overloads the + operator. When I wrote the > code, I specified the left and write operand types. Ok. Although you probably meant "right", not "write". > In C++ it seems as though I can only overload the + operator in > relation to a class. Yes. I guess you learned C++ before Ada; that means you have to work hard to first forget all of your C++ knowledge, and then learn the Ada way :). > I have a structure that contains 3 elements. I want to add a value > to the structure. Please post the code; it is much easier to understand what you are doing with real code to read. Let me guess; you have something like: type Foo_Type is record element_1 : integer; element_2 : integer; element_3 : integer; end record; Now you want to write a function "+" that does something useful with this: function "+" (Left : in Foo_Type; Right : in ???) return Foo_Type; No problem. Just do it :). > Do I need to create a class and the add a value to the object? In Ada, the term "class" refers to a tagged type; you don't need tagged types to define a "+" function. -- -- Stephe