1 つのクラスでのみ使用される定数文字列をいくつか定義する必要があります。次の 3 つのオプションがあるようです。
文字列を使用する場所に直接埋め込みます。
それらをクラスのプライベート静的定数メンバーとして定義します。
//A.h class A { private: static const std::string f1; static const std::string f2; static const std::string f3; }; //A.cpp const std::string f1 = "filename1"; const std::string f2 = "filename2"; const std::string f3 = "filename3"; //strings are used in this file
cpp ファイルの匿名名前空間でそれらを定義します。
//A.cpp namespace { const std::string f1 = "filename1"; const std::string f2 = "filename2"; const std::string f3 = "filename3"; } //strings are used in this file
これらのオプションを考えると、どれをお勧めしますか?またその理由は何ですか? ありがとう。