-5

オンラインの例をいくつか見つけました。

std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
    std::stringstream ss(s);
    std::string item;
    while (std::getline(ss, item, delim)) {
        elems.push_back(item);
    }
    return elems;
}


std::vector<std::string> split(const std::string &s, char delim) {
    std::vector<std::string> elems;
    split(s, delim, elems);
    return elems;
}

スプリットは、その中の他のスプリットを呼び出しています。これは許されますか?2 つの関数は同じ名前ですが、C++ は引数の数に基づいてどちらを使用するかを選択できますか?

また、Event クラスのオブジェクトを文字列で表現する方法を定義しようとしています。これは私のために働くコードです:

inline ostream & operator << (ostream & Str, Event const & event)
{
        //do stuff here    
        return Str;
}

インライン以外で、これの宣言がどのように機能するのかわかりません。(&、演算子、<<、など...)

お時間をいただきありがとうございます。

4

1 に答える 1