From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: Instantiating package problems Date: Sun, 03 Jan 2016 17:08:37 -0500 Organization: A noiseless patient Spider Message-ID: <87poxixqmy.fsf@theworld.com> References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="0d119e765f1ace3a2b3427481b10c030"; logging-data="20947"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bgV/FANpjjmnlJ41ToIS2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:rIQy2LgJbk16rR70qTXFPldkRKc= sha1:G4pQo3sLRnj2IICAzvsDLdBvypo= Xref: news.eternal-september.org comp.lang.ada:29002 Date: 2016-01-03T17:08:37-05:00 List-Id: Andrew Shvets writes: > This is coming from the perspective of someone that has far more C++ OOP > experience. Ada has "packages" and "types". C++ combines these into one feature (the "class"). I suspect that difference explains your confusion. >...Basically, what I'm trying to do is create an instance of a > package and then call a function from that object. There's no such thing as an instance of a package in Ada. An instance of a generic package (which is sort of like a C++ template) is a package, not an object. An instance of a type is an object. >...This is what I have below. > The calculator package is a simple package with the Addition function (which, > you guessed it, just adds numbers together) that takes two integers and returns > an integer. > > I think I'm not quite getting this right or I've misunderstood something. Here > is my code so far and the results that I get when I compile it. > > ========================================================= > with Ada.Text_IO; > > with Calculator; > > procedure Main is > Calc : Calculator; Better to show a complete example. But anyway, Calculator is a package, not a type. I think you can get rid of this line. I'm guessing there are no types declared in Calculator. > begin > ... > > Ada.Text_IO.Put_Line(" Addition: " & Integer'Image(Calc.Addition(52, 31))); I think you can just call Calculator.Addition. I can't be sure without a complete example. By the way, I don't see anything object-oriented in this example. It looks like you're just trying to call a function that is declared in a package -- no need to create any objects here. > Ada.Text_IO.New_Line; > end Main; > > OUTPUT:$ gnatmake -g main.adb calculator.adb You don't need to tell gnatmake all the files. Just the main procedure -- it can find all the other files that need to be [re]compiled based on the "with"s (etc.). - Bob