TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: FRANK ADAM
from: THOMAS MAEDER
date: 1997-11-25 19:41:00
subject: awareness ?

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> };
Sure:
//foo.h
class foo
{
    public:
        foo();
        ~foo();
    private:
        static unsigned int howMany; 
};
//foo.cpp
unsigned int foo::howMany = 0;  
foo::foo()
{ 
    ++howMany; 
    if (howMany>1) 
        ... 
    else 
        ... 
}
foo::~foo() 
{
    --howMany;
}
Thomas
---
 þ MM 1.0 #0113 þ A tree never hits an automobile except in self-defense.
---------------
* Origin: McMeier & Son BBS (2:301/138)

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™.