Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
静的メンバーを含む foo.h にクラスがあります
class foo { public: static vector<int> a; static void Init() { // Init a } }
クラス foo をテストするテスト ファイル foo_test.cpp が作成されるまで、すべて正常に動作します。しかし、テスト ファイルでは、静的メンバー a のみが表示されるため、静的メンバー a は表示されません。これを解決するにはどうすればよいですか?
ありがとう
を定義する必要がありaます。cppファイルに次のような行を追加します。
a
cpp
vector<int> foo::a;
編集:質問の編集を反映するようにデータ型を変更しました
スコープ外でfoo::Init()を呼び出すと、関数の再宣言エラーが発生します。スコープ内に配置すると、未解決の外部シンボルが表示されます。int foo :: a=0としてのみ初期化できます。