my_test.h
#ifndef MY_TEST
#define MY_TEST
struct obj {
int x;
int y;
};
class A {
private:
const static int a=100;
const static obj b;
};
const obj A::b={1,2};
#endif
このヘッダー ファイルを使用して cpp をコンパイルすると、エラー'multiple definition of 'A::b'
が発生します。
- すでにガード マクロを使用しているのに、これはなぜですか?
- エラーが発生しないのはなぜ
A::a
ですか?(私は にコードconst static obj b={1,2}
を書くことができませんclass A
)