* oo programing question
@ 2003-12-06 19:01 shoko
2003-12-06 20:18 ` Stephen Leake
2003-12-07 14:01 ` Martin Krischik
0 siblings, 2 replies; 5+ messages in thread
From: shoko @ 2003-12-06 19:01 UTC (permalink / raw)
i have the following code:
package a is
--car class --
type a is tagged private;
type a_ptr is access all car'class;
--car methods --
private
type a is tagged
record
name:String(1..256);
end record;
end a;
-------------------------------------
with a;
package b is
type b is new a.a with private; <-- constraint error
type b_Ptr is access all b'Class;
function init_b(maximum:positive) return b_Ptr;
private
type b is new a.awith
record
maximum_:positive;
end record;
end b;
-------------------------------------------
in the main procedure:
with a;use a;
with b;use b;
procedure main is
new_b:b_ptr;
begin
new_b := init_b(90);
end main;
i get constraint error on b.ads
i dont understand why
please help
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: oo programing question
2003-12-06 19:01 oo programing question shoko
@ 2003-12-06 20:18 ` Stephen Leake
2003-12-07 14:01 ` Martin Krischik
1 sibling, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2003-12-06 20:18 UTC (permalink / raw)
To: shoko; +Cc: comp.lang.ada
shoko2004@hotmail.com (shoko) writes:
> i have the following code:
After fixing the obvious typos, I get no constraint error. In any
case, you can't get a constraint error just running the compiler;
that's a runtime error. Since you don't provide a body for package b,
I can't run 'main'.
Please post complete, compilable examples. Be sure you run the
compiler on the actual code you post; don't make edits after copying
to your news client. If you are getting a runtime error, show the
execution command line, and the error message you get.
--
-- Stephe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: oo programing question
2003-12-06 19:01 oo programing question shoko
2003-12-06 20:18 ` Stephen Leake
@ 2003-12-07 14:01 ` Martin Krischik
1 sibling, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2003-12-07 14:01 UTC (permalink / raw)
shoko wrote:
> i have the following code:
>
> package a is
> --car class --
> type a is tagged private;
There are two schools here:
1. Packages are multiples and objects are singles:
package Cars is
type Car is ...
2. Packages are singles and objects are Object:
Package Car is
type Object is
Calling the Type the same as the package gets you into trouble when code
becomes more complex.
> type a_ptr is access all car'class;
Use "access" and not "access all" whenever possible.
> with a;
>
> package b is
> type b is new a.a with private; <-- constraint error
> type b_Ptr is access all b'Class;
>
> function init_b(maximum:positive) return b_Ptr;
Are you shure you need a access here? Adas stack handling is far more
powerfull then C++'s. So you might be better of just to return 'b'. Look at
New_Object in
http://adacl.sourceforge.net/html
______Include__AdaCL-SAR-Filter-Replace__adb.htm
> private
> type b is new a.awith
> record
> maximum_:positive;
> end record;
> end b;
> -------------------------------------------
> in the main procedure:
>
> with a;use a;
> with b;use b;
don't "use" everything.
> procedure main is
> new_b:b_ptr;
>
> begin
> new_b := init_b(90);
> end main;
>
> i get constraint error on b.ads
> i dont understand why
Difficult without the package bodys.
With Regards
Martin
--
mailto://krischik@users.sourceforge.net
http://adacl.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* oo programing question
@ 2003-12-07 21:14 shoko
2003-12-08 19:04 ` Martin Krischik
0 siblings, 1 reply; 5+ messages in thread
From: shoko @ 2003-12-07 21:14 UTC (permalink / raw)
here is my generic package:
generic
type Element_Type is private;
package queue is
type Queue is abstract tagged private;
type newqueue is new Queue ;<-- how to create new queue type?
procedure Init( Q: in out Queue) is abstract;
private
type Queue is abstract tagged
record
value:Element_Type;
end record;
end queue;
i need to create a new abstract type(newqueue) that will inherit from Queue.
then need to put the new type(newqueue) in the same generic Queue package,
and to add a new method to the new abstract type.
the reason that the new abstract type(newqueue) should be in the same package is:
i have a type that inherit from Queue
and now i need a new type that inherit from the new abstract type (newqueue)
and will be the same as the one that inherit from Queue.
how can i do it?
thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: oo programing question
2003-12-07 21:14 shoko
@ 2003-12-08 19:04 ` Martin Krischik
0 siblings, 0 replies; 5+ messages in thread
From: Martin Krischik @ 2003-12-08 19:04 UTC (permalink / raw)
shoko wrote:
> here is my generic package:
> generic
> type Element_Type is private;
>
> package queue is
> type Queue is abstract tagged private;
>
> type newqueue is new Queue ;<-- how to create new queue type?
type New_Queue is tagged new Queue with private ;
> procedure Init( Q: in out Queue) is abstract;
Just a thought:
function New_Queue return Queue;
> private
> type Queue is abstract tagged
> record
> value:Element_Type;
> end record;
>
> end queue;
>
> i need to create a new abstract type(newqueue) that will inherit from
> Queue.
>
>
> then need to put the new type(newqueue) in the same generic Queue package,
> and to add a new method to the new abstract type.
>
> the reason that the new abstract type(newqueue) should be in the same
> package is: i have a type that inherit from Queue
> and now i need a new type that inherit from the new abstract type
> (newqueue) and will be the same as the one that inherit from Queue.
This might still be possible with a child package.
With Regards
Martin
--
mailto://krischik@users.sourceforge.net
http://adacl.sourceforge.net
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-12-08 19:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-06 19:01 oo programing question shoko
2003-12-06 20:18 ` Stephen Leake
2003-12-07 14:01 ` Martin Krischik
-- strict thread matches above, loose matches on Subject: below --
2003-12-07 21:14 shoko
2003-12-08 19:04 ` Martin Krischik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox