產生靜態屬性的程式碼

當您產生靜態的程式碼時,所輸入的起始值會產生至陳述式,該陳述式會在類別建構子外部起始設定靜態屬性。請考量下列三個靜態屬性的起始值:
屬性 類型
attr1 int 5
attr2 OMBoolean true
attr3 OMString Shalom"

產生程式碼時,這些值會導致在規格檔案 A.h 中產生下列陳述式:

//-------------------------------------------------
// A.h
//-------------------------------------------------
class A {
////    User explicit entries     ////
protected:
    //## attribute attr3
    static OMString attr3;

    //## attribute attr1
    static int attr1;

    //## attribute attr2
    static OMBoolean attr2;
...
};

在實作檔案 A.cpp 中,會產生下列起始設定碼:

#include "A.h"
//-------------------------------------------------
// A.cpp
//-------------------------------------------------
// Static class member attribute
OMString A::attr3 = "Shalom";

// Static class member attribute
int A::attr1 = 5;

// Static class member attribute
OMBoolean A::attr2 = true;
A::A() {
};

回饋