public static void main

久々にC++でプログラム組んでみた。

動作としては、コマンドラインから与えられた文字列群を出力する。(呼び出し名含む)
ただそれだけ。


main.cpp

#include <vector>
#include <string>
#include <algorithm>
#include "hoge.h"
int main(int arg_num, char** arg_values) try {
    std::vector<std::string> args(arg_values, arg_values + arg_num);
    rf::hoge::hoge::main(args);
} catch(...) {}

hoge.h

#ifndef HOGE_H_INCLUDED
#define HOGE_H_INCLUDED
#include <vector>
#include <string>
namespace rf { namespace hoge {
    class hoge;
} }
class rf::hoge::hoge {
public:
    static void main(const std::vector<std::string>& args);
};
#endif // HOGE_H_INCLUDED

hoge.cpp

#include "hoge.h"
#include <iostream>
#include <algorithm>
#include <iterator>
using rf::hoge::hoge;
void hoge::main(const std::vector<std::string>& args) {
    std::cout << "size : " << args.size() << std::endl;
    std::copy(args.begin(), args.end(),
        std::ostream_iterator<std::string>(std::cout, " "));
}

コンパイル:g++ main.cpp hoge.cpp -ohoge
実行:hoge abc 123 qwe
出力:
size : 4
hoge abc 123 qwe