From: Stephen Leake <Stephe.Leake@nasa.gov>
Subject: Re: Overloading + operator
Date: 25 Aug 2003 09:43:40 -0400
Date: 2003-08-25T13:45:38+00:00 [thread overview]
Message-ID: <u7k51j1ir.fsf@nasa.gov> (raw)
In-Reply-To: u7k52i8se.fsf@earthlink.net
Daniel Allex <dallex@erols.com> 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
prev parent reply other threads:[~2003-08-25 13:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-25 3:25 Overloading + operator Daniel Allex
2003-08-25 5:51 ` Matthew Heaney
2003-08-25 13:43 ` Stephen Leake [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox