comp.lang.ada
 help / color / mirror / Atom feed
From: Andrew Shvets <andrew.shvets@gmail.com>
Subject: Re: Instantiating package problems
Date: Sun, 3 Jan 2016 13:21:52 -0800 (PST)
Date: 2016-01-03T13:21:52-08:00	[thread overview]
Message-ID: <184e9a8d-ec12-4566-9a2d-47bf4d98cfd4@googlegroups.com> (raw)
In-Reply-To: <n6c02h$th7$1@dont-email.me>

Ok, so basically, my way of thinking about OOP in Ada is flawed.  All packages, by default, are static (as well as their methods), but if I want to call a method (procedure/function) I would have to do this on a type that's inside 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++ 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
> > =========================================================
> >


  reply	other threads:[~2016-01-03 21:21 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 [this message]
2016-01-03 21:04 ` Jeffrey R. Carter
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