|
Prev: Building Hibachi
Next: FAST CASH $6 PAYPAL
From: Graham on 3 Apr 2008 11:29 Hi, I'm writing a little financial application. I want to model a stream of payments made at arbitrary periods (the periods are positive numbers; they might be actual dates later on). I think I want to declare this: type Payment_Stream is private; procedure Add_To_Payment_Stream( stream : in out Payment_Stream; period : Positive; amount : Money ); ....... and then privately declare the payment stream as an Ordered Map, like: private package Payment_Stream_Package is new Ada.Containers.Ordered_Maps( Element_Type => Money, Key_Type => Positive ); type Payment_Stream is new Payment_Stream_Package.Map; but I can't do this. Gnat complains that "type derived from tagged type must have extension". I'm fairly new to Ada but thought I was getting on top of it! What is the principal that stops me doing this? What should I do instead? thanks, Graham Stark
From: Robert A Duff on 3 Apr 2008 12:00 Graham <graham.stark(a)virtual-worlds.biz> writes: > type Payment_Stream is new Payment_Stream_Package.Map; > > but I can't do this. Gnat complains that "type derived from tagged > type must have extension". > I'm fairly new to Ada but thought I was getting on top of it! What is > the principal that stops me doing this? What should I do instead? Not really a "principle" -- more like an arbitrary restriction. Map is tagged, and tagged types have to obey that rule. You should say: type Payment_Stream is new Payment_Stream_Package.Map with null record; to create an empty extension. - Bob
From: Dmitry A. Kazakov on 3 Apr 2008 12:02 On Thu, 3 Apr 2008 08:29:28 -0700 (PDT), Graham wrote: > Hi, > I'm writing a little financial application. I want to model a > stream of payments made at arbitrary periods (the periods are positive > numbers; they might be actual dates later on). > > I think I want to declare this: > > > type Payment_Stream is private; > > procedure Add_To_Payment_Stream( > stream : in out Payment_Stream; > period : Positive; > amount : Money ); > > ...... > > and then privately declare the payment stream as an Ordered Map, like: > > private > > package Payment_Stream_Package is new Ada.Containers.Ordered_Maps( > Element_Type => Money, > Key_Type => Positive ); > > type Payment_Stream is new Payment_Stream_Package.Map; type Payment_Stream is new Payment_Stream_Package.Map with null record; > but I can't do this. Gnat complains that "type derived from tagged > type must have extension". -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de
From: Graham on 3 Apr 2008 12:20 On Apr 3, 5:02 pm, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de> wrote: > On Thu, 3 Apr 2008 08:29:28 -0700 (PDT), Graham wrote: > > Hi, > > I'm writing a little financial application. I want to model a > > stream of payments made at arbitrary periods (the periods are positive > > numbers; they might be actual dates later on). > > > I think I want to declare this: > > > type Payment_Stream is private; > > > procedure Add_To_Payment_Stream( > > stream : in out Payment_Stream; > > period : Positive; > > amount : Money ); > > > ...... > > > and then privately declare the payment stream as an Ordered Map, like: > > > private > > > package Payment_Stream_Package is new Ada.Containers.Ordered_Maps( > > Element_Type => Money, > > Key_Type => Positive ); > > > type Payment_Stream is new Payment_Stream_Package.Map; > > type Payment_Stream is new Payment_Stream_Package.Map with null record; > > > but I can't do this. Gnat complains that "type derived from tagged > > type must have extension". > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Oh, I see (I think..) Thanks very much to both of you. Graham
From: Maciej Sobczak on 3 Apr 2008 16:41
On 3 Kwi, 17:29, Graham <graham.st...(a)virtual-worlds.biz> wrote: > package Payment_Stream_Package is new Ada.Containers.Ordered_Maps( > Element_Type => Money, > Key_Type => Positive ); > > type Payment_Stream is new Payment_Stream_Package.Map; Instead of a solution, I have a question: Why do you derive from Map? Which operations of Map do you plan to override? Do you ever plan to pass Payment_Stream where Payment_Stream_Package.Map'Class is expected? What effect would you like to achieved this way? Why derivation and not composition? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com |