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.182.227.137 with SMTP id sa9mr79263059obc.44.1451856452098; Sun, 03 Jan 2016 13:27:32 -0800 (PST) X-Received: by 10.182.112.202 with SMTP id is10mr654546obb.7.1451856452074; Sun, 03 Jan 2016 13:27:32 -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!mv3no25094757igc.0!news-out.google.com!l1ni2412igd.0!nntp.google.com!mv3no25094753igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Jan 2016 13:27:31 -0800 (PST) In-Reply-To: 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> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <425bc374-d508-4e5b-b9ba-09e8cbaaf237@googlegroups.com> Subject: Re: Instantiating package problems From: Andrew Shvets Injection-Date: Sun, 03 Jan 2016 21:27:32 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:29001 Date: 2016-01-03T13:27:31-08:00 List-Id: On Sunday, January 3, 2016 at 4:04:16 PM UTC-5, Jeffrey R. Carter wrote: > On 01/03/2016 11:40 AM, Andrew Shvets wrote: > > > > This is coming from the perspective of someone that has far more C++ OOP > > experience. Basically, what I'm trying to do is create an instance of a > > package and then call a function from that 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. > > First you need to unlearn everything you've learned from using a poorly > designed, error-prone language. > > "Instantiate" in Ada is a technical term that refers to creating a package or > subprogram from a generic. There don't appear to be any generics in your > example, so your subject line is a bit misleading. > > You haven't shown us Calculator, so we can't be sure what you're trying to do, > but I'm going to guess that it looks like > > package Calculator is > function Addition (Left : Integer; Right : Integer) return Integer; > end Calculator; > > If I'm wrong, then you can probably ignore everything else I'm going to say. > > A pkg is a module. It provides encapsulation and information hiding. C++ doesn't > have modules, which are an essential part of any language. A pkg is not a > (sub)type, so you can't declare objects of it. A pkg just is. Once you say > > with Calculator; > > you have Calculator and you can refer to it, just like Ada.Text_IO. What you're > probably trying to do is > > with Ada.Text_IO; > with Calculator; > > procedure Test_Calculator is > -- The declarative part is empty, since no declarations are needed > begin -- Test_Calculator > Ada.Text_IO.Put_Line > (Item => "Addition (52, 31): " & > Integer'Image (Calculator.Addition (52, 31) ) ); > end Test_Calculator; > > -- > Jeff Carter > "Who wears beige to a bank robbery?" > Take the Money and Run > 144 Ok, I see, I think. I suppose a better analogy is how in C you use #include "Some_File.h" and all of the contents of that file just come in and can be used readily, yes? I'm still a little bit lost on the below example: https://en.wikibooks.org/wiki/Ada_Programming/Object_Orientation#Derived_types Basically, an instance of a type inside of a package is created and that is used to work on.