mercredi 20 décembre 2017

Why had to enclose istreambuf_iterator in brackets to make it work?

I have a simple code :

template<class CharT>
class TBufferINI {
public:
    typedef std::basic_string<CharT> string_t;
    typedef const string_t& const_string;

    template< class InputIT >
    TBufferINI(InputIT _Begin, InputIT _End) :
        _Buf(_Begin,_End)
    {}

    string_t GetIni() { return string_t(_Buf.begin(),_Buf.end()); }

private:
    std::vector<CharT> _Buf;
};

int main()
{
    using namespace std;
    ifstream f(R"(Some.ini)");
    assert(f.is_open());

    TBufferINI<char> Ini2(std::istreambuf_iterator<char>(f),std::istreambuf_iterator<char>());
    cout << Ini2.GetIni();
    return 0;
}

gcc give me an error:

main.cpp|38|error: request for member 'GetIni' in 'Ini2', which is of non-class type 'TBufferINI(std::istreambuf_iterator >, std::istreambuf_iterator > (*)())'|

even when I remove cout, nothing will be store in _Buf

but if I enclose the istreambuf_iterator in brackets everything will work as expected

TBufferINI<char> Ini2((std::istreambuf_iterator<char>(f)),std::istreambuf_iterator<char>());

my question is why adding brackets make it happen

Aucun commentaire:

Enregistrer un commentaire