1

Please help me

Error details as follows:

src/a.cpp:2972: undefined reference to `B::XTT collect2: ld returned 1 exit status

B::XTT is a static constant variable in the B struct.

2969     if (index != B::XTT) {
2970         index_map_iter = lookup_index.find(merchandising_index);
2971         merchandising_index = index_map_iter != output_index.end() ? \
2972                index_map_iter->second : B::XTT;

It is very strange that the first time I use B::XTT on line 2969, it does not produce an error. But at 2972 I use B::XTT, and it produces an error.

And if I add -O2 option when I use g++ command, it does not produce an error. But it does produce an error without -O2.

4

1 に答える 1

2

static const メンバー変数を宣言する場合

class foo {
    // omitted other members
    static int MyConst;
};

1 つのコンパイル単位で定義する必要があります。

int foo:MyConst = 42;
于 2013-01-16T12:16:55.870 に答える