0

私はこの問題で数日立ち往生しており、Googleが返信でいっぱいであるにもかかわらず、私の問題に対する答えを見つけることができません。これは非常に抽象的な問題のようです.

Hでの私のコードは次のとおりです。

struct DISPLAYLINE_t {
         char  *text;
         bool isWhite;
         void set(char *txt, bool iswhite){text = txt; isWhite = iswhite;};
};

struct DISPLAY {   
    static DISPLAYLINE_t line1,line2,line3,line4; 
    void clear(){//dostuff};
};

メインからアクセスしようとすると:

DISPLAY::line1.set(string, FALSE);

次のエラーが表示されます。

エラー LNK2019: 未解決の外部シンボル "public: static struct DISPLAYLINE_t DISPLAY::line1" (?line1@DISPLAY@@2UDISPLAYLINE_t@@A) が関数 WinMain で参照されています

何か案は?

4

1 に答える 1

3

You have to provide a definition at global namespace scope for your static data members (at least for those that you are odr-using in your code):

DISPLAYLINE_t DISPLAY::line1;
DISPLAYLINE_t DISPLAY::line2;
DISPLAYLINE_t DISPLAY::line3;
DISPLAYLINE_t DISPLAY::line4;

This live example shows how you should fix your program.

于 2013-04-04T13:34:36.963 に答える