Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Using a generic...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 5532 of 5931
Post > Topic >>

Using a generic instance to implement a public subprogram?

by "Peter C. Chapin" <pchapin@[EMAIL PROTECTED] > Feb 3, 2008 at 01:35 PM

I'm trying to implement a public subprogram (actually several) by 
instantiating a generic. I'm getting an ambiguous (to me) error message 
from GNAT GPL 2007. Here is a complete, compilable example that contains 
the essence of what I'm trying to do:

package Check is
    type Numeric_Type is digits 12;
    type Vector is private;

    function Sqrt(V : Vector) return Vector;
    -- Imagine other operations like Sqrt.

private
    type Vector is array(0..15) of Numeric_Type;

end Check;

The package body defines a generic function for applying an operation to 
a vector and then tries to instantiate it in order to implement function 
Sqrt.

with Ada.Numerics.Generic_Elementary_Functions;

package body Check is

    package Elementary_Functions is
       new Ada.Numerics.Generic_Elementary_Functions(Numeric_Type);

    generic
       with function Operation(Value : Numeric_Type) return Numeric_Type;
    function Unary_Operation(V : Vector) return Vector;

    function Unary_Operation(V : Vector) return Vector is
       Result : Vector;
    begin
       for I in 0 .. 15 loop
          Result(I) := Operation(V(I));
       end loop;
       return Result;
    end;

    function Sqrt is
       new Unary_Operation(Operation => Elementary_Functions.Sqrt);
end Check;

GNAT says this:

check.adb:3:14: missing body for "Sqrt" declared at check.ads:5
check.adb:21:13: "Sqrt" conflicts with declaration at check.ads:5
check.adb:21:13: instantiation cannot provide body for it

The first message I understand. The last two I'm not clear about. Is 
GNAT telling me that my declarations conflict in some way and because of 
that it can't do the instantiation, or is the instantiation the *cause* 
of the conflict? Is it possible to do what I'm trying to do here?

Thanks!

Peter
 




 5 Posts in Topic:
Using a generic instance to implement a public subprogram?
"Peter C. Chapin&quo  2008-02-03 13:35:44 
Re: Using a generic instance to implement a public subprogram?
Gautier <gautier@[EMAI  2008-02-03 20:27:52 
Re: Using a generic instance to implement a public subprogram?
"Peter C. Chapin&quo  2008-02-03 14:46:23 
Re: Using a generic instance to implement a public subprogram?
"Dmitry A. Kazakov&q  2008-02-03 21:37:21 
Re: Using a generic instance to implement a public subprogram?
"Randy Brukardt"  2008-02-04 19:58:52 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:21:44 CDT 2008.