type の static メンバーを宣言するのにいくつか問題があります。std::vector<std::string>
原則として、それを array に置き換えることができstd::string[]
ます。
私は多くの問題を抱えています:それを宣言してstatic
から実装(cppファイル)で初期化すると動作しますが、2番目のファイルの最初のクラスから継承する新しいクラスを作成したい場合、それは不平を言います
error: invalid application of ‘sizeof’ to incomplete type ‘std::string []’
ヘッダーで宣言すると、二重宣言に問題があります。
適切な方法は何ですか?extern を使用する必要がありますか? どのように?
私は:
ファイル_A.h:
class A { public: static string s[]; }
ファイル_A.cpp:
string A::s[] = { ... };
file_B.h
class B : public A
file_B.cpp
void B::function()
{
for (string* s = A::s; s != A::s + sizeof(A::s) / sizeof(string); ++s)
}