基本的には、コンパイラ(g ++)を渡すことができない次のコードです
#include <boost/program_options.hpp>
#include <iostream>
using std::cout;
using std::endl;
namespace po = boost::program_options;
class static_class {
public:
static po::options_description cmd_opt; // here is the definition
};
po::options_description static_class::cmd_opt("dummy");
// the line below cannot pass the compiler !!!
static_class::cmd_opt.add_options()
("help", "show usage info.")
;
main() {
cout << static_class::cmd_opt << endl;
}
エラーメッセージ:
test.cpp:16:1: error: ‘cmd_opt’ in class ‘static_class’ does not name a type
何か案が?
PS小さなコマンドライン環境で処理する必要があるコマンドごとに個別のoptions_descriptionを定義しようとしています。コマンドライン環境を解析するために bison と flex を使用しています。コマンドのすべての引数は、引数の解析のためにこの静的クラスに送信されます。
引数の定義は静的であるため、それらをスタック内のある種のデータ構造にしたくありません (私の考えでは、これは高速でクリーンである可能性があります)。これらのコードは、静的でない場合は問題ないと思いますが、静的な場合はどうなりますか?