comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Instantiating package problems
Date: Sun, 3 Jan 2016 14:04:13 -0700
Date: 2016-01-03T14:04:13-07:00	[thread overview]
Message-ID: <n6c27e$5uq$2@dont-email.me> (raw)
In-Reply-To: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com>

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


  parent reply	other threads:[~2016-01-03 21:04 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-03 18:40 Instantiating package problems Andrew Shvets
2016-01-03 20:27 ` Georg Bauhaus
2016-01-03 21:21   ` Andrew Shvets
2016-01-03 21:04 ` Jeffrey R. Carter [this message]
2016-01-03 21:27   ` Andrew Shvets
2016-01-03 22:39     ` Jeffrey R. Carter
2016-01-03 22:08 ` Bob Duff
2016-01-04  0:07   ` Andrew Shvets
2016-01-04  0:30     ` Andrew Shvets
2016-01-04 13:43       ` G.B.
2016-01-04 14:23       ` Brian Drummond
2016-01-04 20:49     ` Anh Vo
2016-01-04 21:10       ` Dmitry A. Kazakov
2016-01-04 22:39         ` Anh Vo
2016-01-05  1:42           ` Anh Vo
2016-01-05  7:35           ` Dmitry A. Kazakov
2016-01-06  2:46       ` Andrew Shvets
2016-01-06  8:53         ` Dmitry A. Kazakov
2016-01-06  3:30       ` Andrew Shvets
2016-01-06  4:51         ` Anh Vo
2016-01-06  4:54           ` Anh Vo
2016-01-06  5:00           ` Andrew Shvets
2016-01-06  5:07             ` Anh Vo
2016-01-07  4:41               ` Andrew Shvets
2016-01-07  5:41                 ` Anh Vo
2016-01-09 20:14                   ` Andrew Shvets
2016-01-10 19:43                     ` Andrew Shvets
2016-01-10 21:38                       ` Jeffrey R. Carter
2016-01-10 21:50                       ` Georg Bauhaus
2016-01-10 21:58                         ` Andrew Shvets
2016-01-06 13:07             ` G.B.
2016-01-07  4:42               ` Andrew Shvets
2016-01-06 14:25           ` Bob Duff
2016-01-06 23:48             ` Anh Vo
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox