Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Unix.kill on Win32
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-08-06 (14:45)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] static class member....
On Wed, Aug 06, 2003 at 04:57:26PM +0400, Vovka wrote:
> Hi!!!!
> Could you help me please. I'm newbie in ocaml programming, i used to write 
> programmes in C++ , so I've faced    difficulties in introducing  static 
> class member(==a common member for all objects of the same class).  Can i 
> handle it in ocaml? Thanks a lot. 

This is one way to do it, there might be other easier ways:

class foo =
  let counter = ref 0 in
  object (self)
    method incr = counter := !counter + 1
    method show = Printf.printf "counter = %d\n" !counter

let () =
  let obj1 = new foo in
  let obj2 = new foo in

There is an ocaml-beginners list for these sorts of questions, and
I've written a tutorial here:


Richard Jones.
Merjis Ltd. - all your business data are belong to you.
"My karma ran over your dogma"

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: