TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK ADAM
from: JERRY JANKURA
date: 1997-11-24 14:02:00
subject: Awareness ?

FA>Hi,
FA>Is it possible to make a class aware of another instance of itself ?
FA>If it is, how would that be done ?
FA>eg:
FA>class foo
FA>{
FA> foo()
FA> {
FA>  if(we_re_not_alone) ...
FA>   else ...
FA> }
FA>};
Automatically? I think not. But, you can do what you're asking by
careful definition of the class itself and by proper design of the
constructors and destructors:
class foo
{
private:
  static int HowMany:
public:
  foo();
  ~foo();
}
foo::foo()
{
  HowMany ++;
}
foo::~foo()
{
  HowMany --;
}
The integer HowMany is owned by the class, and is not unique to each
object. Let each constructor increment the counter. If the counter
starts at zero, this means that the first instance of the object sets
HowMany to one, the second instance sets it to two, etc. As you destroy
instances, the counter is decremented. Thus, at any time, any instance
of the object can inspect HowMany to determine if it is alone, or if any
other instances exist.  Hope this points the way for you.
-- Jerry
FA> Regards, Frank.   Email: fadam@sensation.net.au.
FA>--- Msged 4.00
---
 * OLXWin 1.00b * I'm in shape ... round's a shape isn't it?
--- InterEcho 1.19
---------------
FA> * Origin: The ticking point, Melbourne, Australia. (3:635/728.21)
* Origin: PC-Ohio PCBoard * Cleveland, OH * 216-381-3320 (1:157/200)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.