Home > Back-end >  Inquire how to define a static global vector array??
Inquire how to define a static global vector array??

Time:10-06

To define the
Vector Snames (4);
Snames [0]="Spring"
Snames [1]="Summer"
Snames [2]="Fall"
Snames [3]="Winter"

Can't figure out how to define it as global static variables, strives for the great god!!!!!

CodePudding user response:

 static STD: : vector Sn (4); 

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
__fastcall TForm20: : TForm20 (TComponent * Owner)
: TForm (the Owner)
{
}

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TForm20: : FormCreate (TObject * Sender)
{

Sn [0]="Spring";
Sn [1]="Summer";
Sn [2]="Fall";
Sn [3]="Winter";
Caption=sn. The size ();
Caption=sn [1];
Caption=sn. The capacity ();

}


This useful?

CodePudding user response:

First define a global static variables:
Vector Snames (4);

Then the initialization:
Void sysInit (void)
{
Snames [0]="Spring";
Snames [1]="Summer";
Snames [2]="Fall".
Snames [3]="Winter".
}
Void sysEnd (void)
{
Snames. The clear ();
}
# pragma startup sysInit//startup: global variable initialization, perform this function,
# pragma exit sysEnd//exit: system perform this function before exit, and then perform a global variable destructor,

C + + realize the initialization section, in this way allows for more than the # pragma startup, but several, execution sequence controlled by the compiler,
  • Related