comp.lang.ada
 help / color / mirror / Atom feed
* On naming space and the good use of qualified expression
@ 2018-01-19 17:51 Mehdi Saada
  2018-01-19 18:37 ` Niklas Holsti
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mehdi Saada @ 2018-01-19 17:51 UTC (permalink / raw)


At that point of the program, I have three "/" operators visibles:
function "/" (A: T_Rational, B: T_Rational) return T_Rational;
function "/" (A: T_Integer, B: T_Integer) return T_Integer;
function "/" (A: T_Integer, B: T_Integer) return T_Rational; -- my constructor method
which makes this expression ambiguous:
Result.Coef(Ind) := Poly_A.Coef(Ind+1) * (Ind+1)/1;
(Coef is an array of T_Rational, Ind is of the same type as the index)

For the first time, I grasp what "namespace polution" means. I overestimated the compiler's smartness. I tried then:
Result.Coef(Ind) := Poly_A.Coef(Ind+1) * T_Rational'((Ind+1)/1);
As I thought qualified expression were a means to inform the compiler of the intended type of the parenthesed expression, so that it could choose based on the litteral inside AND the different visible homonymous functions.
But I got the same error with or without qualified expression:
p_poly_v1_g.adb:82:71: expected private type "T_Rational" defined at p_rationals_g.ads:11, instance at p_poly_v1_g.ads:19
p_poly_v1_g.adb:82:71: found type "Standard.Integer"

Was I mistaken about qualified expressions ?
How can I express myself so that the compiler understand, BESIDES prefixing every single operators with P_Rationals, which is ugly.
I try to understand the use of "use type" and use "all type ...", but I don't manager to for the moment. The language doesn't help, when confronted with new technical stuff. I get it better through exemples...


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

end of thread, other threads:[~2018-01-19 23:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-19 17:51 On naming space and the good use of qualified expression Mehdi Saada
2018-01-19 18:37 ` Niklas Holsti
2018-01-19 18:38 ` AdaMagica
2018-01-19 18:55 ` Jeffrey R. Carter
2018-01-19 23:23   ` Mehdi Saada

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