From: Andrew Shvets <andrew.shvets@gmail.com>
Subject: Re: Instantiating package problems
Date: Sun, 3 Jan 2016 16:07:28 -0800 (PST)
Date: 2016-01-03T16:07:28-08:00 [thread overview]
Message-ID: <b5dcba43-8652-40f0-8115-a235c6c83544@googlegroups.com> (raw)
In-Reply-To: <87poxixqmy.fsf@theworld.com>
Hi Bob,
Thanks for writing back. This is the entire example:
http://pastebin.com/GEJT3WzL
Thanks for the tip on compiling.
On Sunday, January 3, 2016 at 5:08:53 PM UTC-5, Bob Duff wrote:
> Andrew Shvets <andre.....@gmail.com> writes:
>
> > This is coming from the perspective of someone that has far more C++ OOP
> > experience.
>
> Ada has "packages" and "types". C++ combines these into one feature
> (the "class"). I suspect that difference explains your confusion.
>
> >...Basically, what I'm trying to do is create an instance of a
> > package and then call a function from that object.
>
> There's no such thing as an instance of a package in Ada.
> An instance of a generic package (which is sort of like a C++ template)
> is a package, not an object. An instance of a type is
> an 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.
> >
> > I think I'm not quite getting this right or I've misunderstood something. Here
> > is my code so far and the results that I get when I compile it.
> >
> > =========================================================
> > with Ada.Text_IO;
> >
> > with Calculator;
> >
> > procedure Main is
> > Calc : Calculator;
>
> Better to show a complete example.
>
> But anyway, Calculator is a package, not a type.
> I think you can get rid of this line.
> I'm guessing there are no types declared in Calculator.
>
> > begin
> > ...
> >
> > Ada.Text_IO.Put_Line(" Addition: " & Integer'Image(Calc.Addition(52, 31)));
>
> I think you can just call Calculator.Addition. I can't be sure without
> a complete example.
>
> By the way, I don't see anything object-oriented in this example.
> It looks like you're just trying to call a function that is declared
> in a package -- no need to create any objects here.
>
> > Ada.Text_IO.New_Line;
> > end Main;
> >
> > OUTPUT:$ gnatmake -g main.adb calculator.adb
>
> You don't need to tell gnatmake all the files. Just the main
> procedure -- it can find all the other files that need to be
> [re]compiled based on the "with"s (etc.).
>
> - Bob
next prev parent reply other threads:[~2016-01-04 0:07 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
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 [this message]
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