Xref: utzoo comp.lang.c++:12828 comp.std.c++:821 comp.object:3130 Newsgroups: comp.lang.c++,comp.std.c++,comp.object Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!t500e0!fuchs From: fuchs@t500e0.telematik.informatik.uni-karlsruhe.de (Harald Fuchs) Subject: Re: C++ possible new construct proposal Message-ID: Sender: news@ira.uka.de (USENET News System) Organization: University of Karlsruhe, FRG References: <1991Apr11.155803.5410@mnemosyne.cs.du.edu> Date: Fri, 12 Apr 1991 12:38:11 GMT Lines: 62 cag@mnemosyne.cs.du.edu (Chris Gantz) writes: > class X { > type: > private: > // internal data representation for type; > int no_instantiations; > protected: > // protected interface for type; > public: > int instantaitions() { > return instantiations; > } > void update_instantiations() { > no_instantitations++; > } > object: > private: > // internal data representation for objects; > protected: > // protected interface for objects; > public: > X() { // default constructor > update_instantiations() > // object appropriate internal data initialization. > } > ~X() { } > void f() { } > }; > main() > { > X x_obj; > x_obj.f(); // using x_obj through the object public interface > // below is an example of using the type X as an object... > no_current_instantiations = X.instantiations(); > > } Your proposed addition has been done in C++ version 2. It's called "static member functions": class X { static int no_instantiations; static void update_instantiations() { no_instantitations++; } public: X () { update_instantiations(); } static int instantiations () { return no_instantiations; } void f (); }; main () { X x_obj; x_obj.f (); no_current_instantiations = X::instantiations (); // or x_obj.instantiations () } -- Harald Fuchs