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: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Instantiating package problems Date: Sun, 3 Jan 2016 14:04:13 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Sun, 3 Jan 2016 21:01:36 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="6106"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18immbc1jqT2/HEZ/phF+6JjC2egYqu8mU=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:sILQ2DfIF/y7rWMkG7dKEM8jlNE= Xref: news.eternal-september.org comp.lang.ada:28999 Date: 2016-01-03T14:04:13-07:00 List-Id: 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