Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI651.ASC

 
Output of file : TI651.ASC contained in archive : BCPPTECH.ZIP







PRODUCT : C++ NUMBER : 651
VERSION : All
OS : PC DOS
DATE : February 25, 1992 PAGE : 1/1

TITLE : Initializing Static Class Members of Type Class




/* IMPORTANT! When testing static member initialization, you must
declare an instance of the class in a main function; otherwise, the
linker has no reference which it must try to resolve, and the
undefined symbol error will not be seen--thus you won't know that
your initialization was in error.
*/

//declare a class
class First {
public:
int count;
First() {} //must have callable constructor
};

//declare class containing static member of class First
class Second {
public:
static First fVar;
};

//initialize static member of class Second
First Second::fVar = First(); //initialize with explicit call to ctor

int main(void)
{
Second *sVarA = new Second;
delete sVarA;
return 0;
}






















  3 Responses to “Category : C Source Code
Archive   : BCPPTECH.ZIP
Filename : TI651.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/