* oo programing help needed?
@ 2003-12-06 10:21 shoko
2003-12-06 12:23 ` Georg Bauhaus
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: shoko @ 2003-12-06 10:21 UTC (permalink / raw)
i have the following:
------------------------------------------
package one is
type one is tagged private;
type one_ptr is access all one'class;
procedure set_name(name:String;this:in out one);
function get_name(this:one) return string;
private
type one is tagged
record
name:String(1..256);
end record;
end one ;
---------------------------------------------
with one;
package two is
type two is new one.one with private ;
private
type two is new one.one with null record;
end two;
---------------------------------------------
with two;
package three is
type three is new two.two with private ;
function get_name(this:three) return string;
private
type three is new two.two with null record;
end two;
-------------------------------------------
package body three is
function get_name(this:three) return string
s:string(1..10);
begin
return s+ this.name; <-- no selector "name" for type three
end get_name;
end three;
i get no selector "name" for type three
how to solve this problem??????
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: oo programing help needed?
2003-12-06 10:21 oo programing help needed? shoko
@ 2003-12-06 12:23 ` Georg Bauhaus
2003-12-06 14:11 ` Stephen Leake
2003-12-06 13:46 ` Martin Krischik
2003-12-07 2:42 ` Jeffrey Carter
2 siblings, 1 reply; 6+ messages in thread
From: Georg Bauhaus @ 2003-12-06 12:23 UTC (permalink / raw)
shoko <shoko2004@hotmail.com> wrote:
: i have the following:
: ------------------------------------------
: package one is
: type one is tagged private;
: type one_ptr is access all one'class;
:
: procedure set_name(name:String;this:in out one);
: function get_name(this:one) return string;
:
: private
: type one is tagged
: record
: name:String(1..256);
: end record;
:
:
: end one ;
...
: -------------------------------------------
: package body three is
: function get_name(this:three) return string
: s:string(1..10);
: begin
: return s+ this.name; <-- no selector "name" for type three
: end get_name;
In the definition of one in package one, you have chosen to
hide .name from view. But then you select a .name component
from within the body of package three, which as a package
is just any package, and thus cannot see the private
part of package one. (You could use get_name in three
because it is not in the private part of one. This might
be a good thing to do anyway as it respects the contract
for dealing with ones using one's public operations.)
-- Georg
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: oo programing help needed?
2003-12-06 10:21 oo programing help needed? shoko
2003-12-06 12:23 ` Georg Bauhaus
@ 2003-12-06 13:46 ` Martin Krischik
2003-12-07 2:42 ` Jeffrey Carter
2 siblings, 0 replies; 6+ messages in thread
From: Martin Krischik @ 2003-12-06 13:46 UTC (permalink / raw)
shoko wrote:
> i have the following:
> ------------------------------------------
> package one is
> type one is tagged private;
> type one_ptr is access all one'class;
>
> procedure set_name(name:String;this:in out one);
> function get_name(this:one) return string;
>
> private
> type one is tagged
> record
> name:String(1..256);
> end record;
>
>
> end one ;
> ---------------------------------------------
> with one;
>
> package two is
> type two is new one.one with private ;
> private
> type two is new one.one with null record;
> end two;
> ---------------------------------------------
> with two;
>
> package three is
> type three is new two.two with private ;
> function get_name(this:three) return string;
> private
> type three is new two.two with null record;
> end two;
>
> -------------------------------------------
> package body three is
> function get_name(this:three) return string
> s:string(1..10);
> begin
> return s+ this.name; <-- no selector "name" for type three
> end get_name;
>
> end three;
>
>
> i get no selector "name" for type three
>
> how to solve this problem??????
three is not a child packages of one. While it it true that "private" is
more like "protected" in C++ and Java it is also part of the package. So
only child packages can acces the private section - child classes can't do
that. Java has something similar but I can't remember the actual syntax
(something like private proctected or protected private or so).
With Regards
Martin
--
mailto://krischik@users.sourceforge.net
http://adacl.sourceforge.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: oo programing help needed?
2003-12-06 12:23 ` Georg Bauhaus
@ 2003-12-06 14:11 ` Stephen Leake
2003-12-06 15:50 ` Steve
0 siblings, 1 reply; 6+ messages in thread
From: Stephen Leake @ 2003-12-06 14:11 UTC (permalink / raw)
To: Georg Bauhaus; +Cc: comp.lang.ada
Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:
> shoko <shoko2004@hotmail.com> wrote:
> : i have the following:
> : ------------------------------------------
> : package one is
> : type one is tagged private;
> : type one_ptr is access all one'class;
> :
> : procedure set_name(name:String;this:in out one);
> : function get_name(this:one) return string;
> :
> : private
> : type one is tagged
> : record
> : name:String(1..256);
> : end record;
> :
> :
> : end one ;
> ...
> : -------------------------------------------
> : package body three is
> : function get_name(this:three) return string
> : s:string(1..10);
> : begin
> : return s+ this.name; <-- no selector "name" for type three
> : end get_name;
>
>
> In the definition of one in package one, you have chosen to
> hide .name from view. But then you select a .name component
> from within the body of package three, which as a package
> is just any package, and thus cannot see the private
> part of package one. (You could use get_name in three
> because it is not in the private part of one. This might
> be a good thing to do anyway as it respects the contract
> for dealing with ones using one's public operations.)
Or, you can make packages Two and Three child packages of One; then
they have visibility to the private part of One.
Which approach is correct depends on what your full application is.
--
-- Stephe
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: oo programing help needed?
2003-12-06 14:11 ` Stephen Leake
@ 2003-12-06 15:50 ` Steve
0 siblings, 0 replies; 6+ messages in thread
From: Steve @ 2003-12-06 15:50 UTC (permalink / raw)
"Stephen Leake" <stephen_leake@acm.org> wrote in message
news:mailman.29.1070719903.31149.comp.lang.ada@ada-france.org...
> Georg Bauhaus <sb463ba@l1-hrz.uni-duisburg.de> writes:
>
> > shoko <shoko2004@hotmail.com> wrote:
> > : i have the following:
> > : ------------------------------------------
> > : package one is
> > : type one is tagged private;
> > : type one_ptr is access all one'class;
> > :
> > : procedure set_name(name:String;this:in out one);
> > : function get_name(this:one) return string;
> > :
> > : private
> > : type one is tagged
> > : record
> > : name:String(1..256);
> > : end record;
> > :
> > :
> > : end one ;
> > ...
> > : -------------------------------------------
> > : package body three is
> > : function get_name(this:three) return string
> > : s:string(1..10);
> > : begin
> > : return s+ this.name; <-- no selector "name" for type three
> > : end get_name;
> >
> >
> > In the definition of one in package one, you have chosen to
> > hide .name from view. But then you select a .name component
> > from within the body of package three, which as a package
> > is just any package, and thus cannot see the private
> > part of package one. (You could use get_name in three
> > because it is not in the private part of one. This might
> > be a good thing to do anyway as it respects the contract
> > for dealing with ones using one's public operations.)
>
> Or, you can make packages Two and Three child packages of One; then
> they have visibility to the private part of One.
>
> Which approach is correct depends on what your full application is.
>
> --
> -- Stephe
>
Another alternative (assuming get_name(this:one) does the obvious):
with one;
package body three is
function get_name(this:three) return string is
s:string(1..10);
begin
return s & one.get_name(one.one(this));
end get_name;
end three;
BTW: It doesn't really take that much extra effort to actually run code you
post through the compiler. If you had done so you would have had a few
other errors:
package three is
...
end two; <-- Package name doesn't match
package body three is
function get_name(this:three) return string <-- Missing "is"
s:string(1..10);
The "+" operator is not defined to concatenate two strings. Use "&"
instead.
It's easy to save newsgroup posts and run gnatchop to get source files to
test. It is annoying when the files generated don't compile due to errors
in the source.
Steve
(The Duck)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: oo programing help needed?
2003-12-06 10:21 oo programing help needed? shoko
2003-12-06 12:23 ` Georg Bauhaus
2003-12-06 13:46 ` Martin Krischik
@ 2003-12-07 2:42 ` Jeffrey Carter
2 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Carter @ 2003-12-07 2:42 UTC (permalink / raw)
shoko wrote:
> return s+ this.name; <-- no selector "name" for type three
Where is "+" defined? If you haven't defined it, it doesn't exist, and
this indicates that you need to learn Ada's basics better before you
start messing around with its OO features.
--
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-12-07 2:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-06 10:21 oo programing help needed? shoko
2003-12-06 12:23 ` Georg Bauhaus
2003-12-06 14:11 ` Stephen Leake
2003-12-06 15:50 ` Steve
2003-12-06 13:46 ` Martin Krischik
2003-12-07 2:42 ` Jeffrey Carter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox