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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.50.132.9 with SMTP id oq9mr45081142igb.3.1451866049045; Sun, 03 Jan 2016 16:07:29 -0800 (PST) X-Received: by 10.182.242.6 with SMTP id wm6mr527860obc.18.1451866049027; Sun, 03 Jan 2016 16:07:29 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!mv3no25133860igc.0!news-out.google.com!f6ni42441igq.0!nntp.google.com!mv3no25133852igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Jan 2016 16:07:28 -0800 (PST) In-Reply-To: <87poxixqmy.fsf@theworld.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:18f:900:8350:ba86:87ff:fed6:5907; posting-account=3pYsyQoAAACcI-ym7XtMOI2PDU8gRZS5 NNTP-Posting-Host: 2601:18f:900:8350:ba86:87ff:fed6:5907 References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> <87poxixqmy.fsf@theworld.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Instantiating package problems From: Andrew Shvets Injection-Date: Mon, 04 Jan 2016 00:07:29 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:29004 Date: 2016-01-03T16:07:28-08:00 List-Id: Hi Bob, Thanks for writing back. This is the entire example: http://pastebin.com/GEJT3WzL Thanks for the tip on compiling. On Sunday, January 3, 2016 at 5:08:53 PM UTC-5, Bob Duff wrote: > 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