0

クラス A には、最初にオブジェクトを文字列ストリームに渡し、次にストリームを文字列に変換することにより、オブジェクトを文字列に読み取るテンプレート関数が含まれています。

私の人生では、なぜこれらのオブジェクトがストリームに渡されないのかわかりません。何が問題なのですか?これを解決するにはどうすればよいですか?

class A
{
public:

    template<class T>
    void Input(const T&);

private:
    std::string result;
};

template<class T>
void A::Input(const T& obj)
{
    //Pass object to the stream
    std::ostringstream ss;
    ss << obj;

    //After this line, result == "" with size 1 (??), no matter the input
    result = ss.str();

    int test = 1234;
    ss << test;

    //Even with a test int, result == "" with size 1 (???)
    result = ss.str();
}

編集: Visual Studio Pro 2012 を使用しています。

4

0 に答える 0