🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.oodesign
Article #2

Counting the number of instances of a user defined class

#2
From: Pang Fu
Date: Tue, 08 Jul 2003 05:42
26 lines
1669 bytes
How to count how many instances are created of a user defined class?

In the following example how TMyClass can count the number of instances
(objects created from TMyClass) ?

class TMyClass
{
private :
  static int InstanceCount;
public :
 TMyClass(){
   InstanceCount ++; <--?? How to start from zero and increment?
 }
  ~TMyClass();
};
...
const int N= 456;
for (int i=0; i<N; i++){
  TMyClass *MyObj = new TMyClass();
}

AnsiString S;
S.sprintf("Instance Count :%d", ????How????);

Pang Fu
nospam_pangfu@hotmail.com
Technical Details
Message-ID: <3f0a59ff@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.wirehub.nl!news.kweb.on.ca!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10db1e,bcc8bd10d54dd071,start
X-Google-Attributes: gid10db1e,public
X-Google-Thread: 102541,bcc8bd10d54dd071,start
X-Google-Attributes: gid102541,public
X-Google-ArrivalTime: 2003-07-07 23:01:21 PST
From: "Pang Fu" <nospam_pangfu@hotmail.com>
Newsgroups: borland.public.cppbuilder.oodesign,borland.public.cppbuilder.students
Subject: Counting the number of instances of a user defined class
Date: Tue, 8 Jul 2003 15:42:14 +1000
Lines: 31
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 203.134.37.4
Message-ID: <3f0a59ff@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1057643007 203.134.37.4 (7 Jul 2003 22:43:27 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-04!sn-xit-06!sn-xit-09!supernews.com!newsfeed.gamma.ru!Gamma.RU!newsfeed.media.kyoto-u.ac.jp!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!newsfeed.wirehub.nl!news.kweb.on.ca!newsgroups.borland.com!not-for-mail