comp.lang.ada
 help / color / mirror / Atom feed
From: Vinzent 'Gadget' Hoefler <nntp-2004-12@t-domaingrabbing.de>
Subject: Re: overloading operators with private variables
Date: Wed, 29 Dec 2004 17:22:33 +0000
Date: 2004-12-29T17:22:33+00:00	[thread overview]
Message-ID: <16484311.lexTNh36f7@jellix.jlfencey.com> (raw)
In-Reply-To: 1104336536.856474.279370@f14g2000cwb.googlegroups.com

R wrote:

> 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;

Yes, classical beginner's problem. ;-)

I suppose you have the according "with"-clauses in there, right?
Remember that "with" doesn't make anything visible, and that's the
problem: function testclass."*" is not visible, function Standard."*"
is (it always is), but expects different types of parameters, of
course. So there are three possible solutions:

1) objectMul := testclass."*"(object, object2)

It's clean, it says where it's coming from, it works. So it's perfect,
isn't it? --- No? You're right. In most cases you don't want that,
because if you would have wanted a function call that really looks like
a function call, you would have declared it that way. ;-)

So there's solution

2) Insert a "use type testclass.rec1" clause at the beginning to make
these _operations_ on the type directly visible. This is what I would
suggest and this is what one usually wants.

Well, there's still solution

3) Insert a "use testclass" clause at the beginning to make everything
from testclass directly visible. Most people consider this a bad idea,
and they're right, for different reasons. So I wouldn't recommend it
neither.

So for now it's best to forget about solution 3.


Vinzent.



  reply	other threads:[~2004-12-29 17:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-29 16:08 overloading operators with private variables R
2004-12-29 17:22 ` Vinzent 'Gadget' Hoefler [this message]
2005-01-10  3:35 ` Dave Thompson
replies disabled

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