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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC,WEIRD_PORT autolearn=no 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: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Instantiating package problems Date: Sun, 3 Jan 2016 21:27:28 +0100 Organization: A noiseless patient Spider Message-ID: References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 3 Jan 2016 20:24:49 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="11b7797518b1fb8db630a6211ab1c6df"; logging-data="30247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RdhRmsi9Zo5pZZJNvw3M0s85H4OryYdw=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 In-Reply-To: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> Cancel-Lock: sha1:1OKvkdXy5AUzU8xeUqy3dViSd1g= Xref: news.eternal-september.org comp.lang.ada:28998 Date: 2016-01-03T21:27:28+01:00 List-Id: On 03.01.16 19:40, Andrew Shvets wrote: > Hi all, > > 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. The C++ equivalent of a generic package of Ada would be (a) a generic namespace (with an optional block of statements that are executed when the namespace is elaborated), or (b) a generic file that has, alongside any definitions, also said block of statements. 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. "Calculator" of your example names a package, but not a (sub)type, this is what the compiler says in its first message. 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. > 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 > ========================================================= >