comp.lang.ada
 help / color / mirror / Atom feed
* Overloading + operator
@ 2003-08-25  3:25 Daniel Allex
  2003-08-25  5:51 ` Matthew Heaney
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Allex @ 2003-08-25  3:25 UTC (permalink / raw)


I have some Ada code that overloads the + operator.  When I wrote the
code, I specified the left and write operand types.  In C++ it seems as
though I can only overload the + operator in relation to a class.  I
have a structure that contains 3 elements.  I want to add a value to the
structure.  Do I need to create a class and the add a value to the
object?






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Overloading + operator
  2003-08-25  3:25 Overloading + operator Daniel Allex
@ 2003-08-25  5:51 ` Matthew Heaney
  2003-08-25 13:43   ` Stephen Leake
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 2003-08-25  5:51 UTC (permalink / raw)


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.  In C++ it seems
> as though I can only overload the + operator in relation to a class.

Yes, you can override the predefined "+" operation in Ada.


> I have a structure that contains 3 elements.  I want to add a value to
> the structure.  Do I need to create a class and the add a value to the
> object?

Why don't you just add it?  Why can't you simply modify the code?






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Overloading + operator
  2003-08-25  5:51 ` Matthew Heaney
@ 2003-08-25 13:43   ` Stephen Leake
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2003-08-25 13:43 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-08-25 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-25  3:25 Overloading + operator Daniel Allex
2003-08-25  5:51 ` Matthew Heaney
2003-08-25 13:43   ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox