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, WEIRD_PORT autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.28.41 with SMTP id y9mr48280076obg.14.1451856112627; Sun, 03 Jan 2016 13:21:52 -0800 (PST) X-Received: by 10.182.250.169 with SMTP id zd9mr653936obc.1.1451856112595; Sun, 03 Jan 2016 13:21:52 -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!mv3no25092878igc.0!news-out.google.com!l1ni2412igd.0!nntp.google.com!mv3no25092867igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 3 Jan 2016 13:21:52 -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: <184e9a8d-ec12-4566-9a2d-47bf4d98cfd4@googlegroups.com> Subject: Re: Instantiating package problems From: Andrew Shvets Injection-Date: Sun, 03 Jan 2016 21:21:52 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:29000 Date: 2016-01-03T13:21:52-08:00 List-Id: Ok, so basically, my way of thinking about OOP in Ada is flawed. All packa= ges, by default, are static (as well as their methods), but if I want to ca= ll a method (procedure/function) I would have to do this on a type that's i= nside of a package, yes? On Sunday, January 3, 2016 at 3:27:29 PM UTC-5, Georg Bauhaus wrote: > On 03.01.16 19:40, Andrew Shvets wrote: > > Hi all, > > > > This is coming from the perspective of someone that has far more C++ OO= P 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 bel= ow. 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. >=20 > The C++ equivalent of a generic package of Ada would be >=20 > (a) a generic namespace (with an optional block of statements > that are executed when the namespace is elaborated), or >=20 > (b) a generic file that has, alongside any definitions, also said block > of statements. >=20 > C++ is different from Ada in this regard, since it has generic types > only and none of the above, except for preprocessor tricks. > Ada, OTOH, does not have generic types, only generic units (possibly > containing types) such as packages and subprograms. >=20 > "Calculator" of your example names a package, but not a (sub)type, > this is what the compiler says in its first message. >=20 > If it is a generic package, then you'd be instantiating packages > from it, but not objects. Again, unlike C++, which provides for > some automatically inferred instantiations, Ada requires that > generic units be instantiated explicitly. >=20 > > OUTPUT:$ gnatmake -g main.adb calculator.adb > > gcc -c -g main.adb > > main.adb:10:10: subtype mark required in this context > > main.adb:10:10: found "calculator" declared at calculator.ads:5 > > main.adb:22:60: invalid prefix in selected component "Calc" > > gnatmake: "main.adb" compilation error > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D > >