Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Protected methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Dmitry Bely <dbely@m...>
Subject: Re: [Caml-list] Protected methods
Alessandro Baretta <alex@baretta.com> writes:

>> Do not private Ocaml methods have in fact "protected" C++ semantics? They
>> cannot be called directly but can be used in methods of inherited
>> classes...
>> - Dmitry Bely
>
> I thought so, too. I made several atttempts, and the compiler seemed
> to reject all of them. Let me see if I can cook up a quick example.
>
> # class a = object method private m : unit = (new a) # m end;;
> The expression "new a" has type a = <  > but is used with type
>    < m : unit; .. >
> Only the second object type has a method m

That's because Ocaml private methods can only be applied to the "self" or
"super" object, not to other class instances. Obviously, an object
hierarchy has nothing to do with a class hierarchy (C++'s "private" and
"protected" just ignore existence of the first one, and IMHO that is not
good). But why do you need to call other instance's private/protected
methods? Maybe you should slightly change your design? Could you roughly
describe your task?

- Dmitry Bely


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners