* Re: problem with operation
1998-05-09 0:00 problem with operation Bernhard Rumpler
@ 1998-05-09 0:00 ` Matthew Heaney
1998-05-09 0:00 ` Michael F Brenner
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1998-05-09 0:00 UTC (permalink / raw)
In article <01bc5cbd$c4565da0$LocalHost@default>, "Bernhard Rumpler"
<b.rumpler@gmx.net> wrote:
(start of quote)
I don't know how to use the operation "+" with a private type.
("left operand has private type "Element_Typ" defined at
Matrizen_Operationen.ads, right operand has.." ..the same type) I simply
want to add the Operands as if they were of type Integer, real or sth. like
that.
GENERIC
TYPE Element_Typ IS PRIVATE;
(end of quote)
Here is your problem. You haven't imported addition of elements as a
operation. So do this:
with function "+"
(L, R : Element_Type) return Element_Type is <>;
(start of quote)
Z_S_Zahl : NATURAL;
PACKAGE Matrizen_Operationen IS
TYPE Matrix IS PRIVATE;
FUNCTION "+" (M1,M2: IN Matrix)RETURN Matrix;
FUNCTION "*" (M1,M2: IN Matrix)RETURN Matrix;
PRIVATE
TYPE Matrix IS ARRAY (1..Z_S_Zahl, 1..Z_S_Zahl)OF Element_Typ;
END Matrizen_Operationen;
PACKAGE BODY Matrizen_Operationen IS
FUNCTION "+" (M1,M2: IN Matrix) RETURN Matrix IS
i,j: INTEGER;
M3: Matrix;
BEGIN
FOR i IN 1..Z_S_Zahl LOOP
FOR j IN 1..Z_S_Zahl LOOP
M3(i,j) := M1(i,j)+M2(i,j); -- <-- HERE!!!!
END LOOP;
END LOOP;
RETURN M3;
END;
FUNCTION "*" (M1,M2: IN Matrix) RETURN Matrix IS
M3: Matrix;
BEGIN
RETURN M3;
END;
END Matrizen_Operationen;
(end of quote)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: problem with operation
1998-05-09 0:00 problem with operation Bernhard Rumpler
1998-05-09 0:00 ` Matthew Heaney
@ 1998-05-09 0:00 ` Michael F Brenner
1998-05-09 0:00 ` Robert Dewar
1 sibling, 1 reply; 4+ messages in thread
From: Michael F Brenner @ 1998-05-09 0:00 UTC (permalink / raw)
Since the elements of the matrix are private, they do not carry
with them any + operators. One way to repair this is to give
the generic matrix package that + operator in addition to the element
type, like this:
generic
...
type elements is private;
with function "+" (left, right: elements) return elements;
...
package fixed_matrix_essence is
type fixed_matrices is private;
...
function "+" (left, right: fixed_matrices) return fixed_matrices;
...
The body will then be able to add elements, because you gave it
the function + for elements.
Other possibilities include: derived or other global operations,
or a non-private element type for the matrices.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: problem with operation
1998-05-09 0:00 ` Michael F Brenner
@ 1998-05-09 0:00 ` Robert Dewar
0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1998-05-09 0:00 UTC (permalink / raw)
Michael said
<< generic
...
type elements is private;
with function "+" (left, right: elements) return elements;
>>
But forgot to add the "is <>" which is obviously very appropriate here,
and is likely the solution that is sought!
^ permalink raw reply [flat|nested] 4+ messages in thread
* problem with operation
@ 1998-05-09 0:00 Bernhard Rumpler
1998-05-09 0:00 ` Matthew Heaney
1998-05-09 0:00 ` Michael F Brenner
0 siblings, 2 replies; 4+ messages in thread
From: Bernhard Rumpler @ 1998-05-09 0:00 UTC (permalink / raw)
Hi!
I please help me with the following problem: (i'm a beginner)
I don't know how to use the operation "+" with a private type.
("left operand has private type "Element_Typ" defined at
Matrizen_Operationen.ads, right operand has.." ..the same type) I simply
want to add the Operands as if they were of type Integer, real or sth. like
that.
GENERIC
TYPE Element_Typ IS PRIVATE;
Z_S_Zahl : NATURAL;
PACKAGE Matrizen_Operationen IS
TYPE Matrix IS PRIVATE;
FUNCTION "+" (M1,M2: IN Matrix)RETURN Matrix;
FUNCTION "*" (M1,M2: IN Matrix)RETURN Matrix;
PRIVATE
TYPE Matrix IS ARRAY (1..Z_S_Zahl, 1..Z_S_Zahl)OF Element_Typ;
END Matrizen_Operationen;
PACKAGE BODY Matrizen_Operationen IS
FUNCTION "+" (M1,M2: IN Matrix) RETURN Matrix IS
i,j: INTEGER;
M3: Matrix;
BEGIN
FOR i IN 1..Z_S_Zahl LOOP
FOR j IN 1..Z_S_Zahl LOOP
M3(i,j) := M1(i,j)+M2(i,j); -- <-- HERE!!!!
END LOOP;
END LOOP;
RETURN M3;
END;
FUNCTION "*" (M1,M2: IN Matrix) RETURN Matrix IS
M3: Matrix;
BEGIN
RETURN M3;
END;
END Matrizen_Operationen;
Bernhard Rumpler <b.rumpler@gmx.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1998-05-09 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-09 0:00 problem with operation Bernhard Rumpler
1998-05-09 0:00 ` Matthew Heaney
1998-05-09 0:00 ` Michael F Brenner
1998-05-09 0:00 ` Robert Dewar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox