From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA21899; Wed, 6 Aug 2003 16:45:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA24959 for ; Wed, 6 Aug 2003 16:45:25 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h76EjPf09593 for ; Wed, 6 Aug 2003 16:45:25 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19kPXX-0007iw-00; Wed, 06 Aug 2003 15:45:23 +0100 Date: Wed, 6 Aug 2003 15:45:23 +0100 To: Vovka Cc: caml-list@inria.fr Subject: Re: [Caml-list] static class member.... Message-ID: <20030806144523.GA29653@redhat.com> References: <000201c35c17$2cefc4a0$0300a8c0@James> <200308061657.26300.jove@newmail.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200308061657.26300.jove@newmail.ru> User-Agent: Mutt/1.5.4i From: Richard Jones X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 0400,:01 newbie:01 foo:01 incr:01 printf:01 freshmeat:01 ltd:98 ocaml:01 06,:02 objects:02 business:96 wrote:03 obj:03 object:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 end let () = let obj1 = new foo in let obj2 = new foo in obj1#incr; obj2#incr; obj1#show; obj2#show There is an ocaml-beginners list for these sorts of questions, and I've written a tutorial here: http://merjis.com/richj/computers/ocaml/tutorial/ Rich. -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. "My karma ran over your dogma" ------------------- 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