This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

istringstream.rdbuf with custom streambuf does not compile


IÂhaveÂtheÂfollowingÂsimpleÂtestÂcodeÂ(t.cxx):

#includeÂ<streambuf>
#includeÂ<sstream>
usingÂnamespaceÂstd;

classÂFileBuf:ÂpublicÂstreambuf
{
};

intÂmain(intÂargc,Âchar**Âargv)

{
ÂÂÂÂFileBufÂfbuf;
ÂÂÂÂistringstreamÂiss;
ÂÂÂÂ//ÂTheÂfollowingÂlineÂdoesÂnotÂcompile!
ÂÂÂÂiss.rdbuf(&fbuf);

ÂÂÂÂreturnÂ0;
}

WhenÂcompilingÂtheÂaboveÂcodeÂusingÂg++Â(versionÂ5.3.1Â20160406Â(RedÂHatÂ5.3.1-6)),ÂIÂgotÂveryÂstrangeÂerrors:

$Âg++Â-oÂtÂt.cxx
t.cxx:ÂInÂfunctionÂâintÂmain(int,Âchar**)â:
t.cxx:14:17:Âerror:ÂnoÂmatchingÂfunctionÂforÂcallÂtoÂâstd::__cxx11::basic_istringstream<char>::rdbuf(FileBuf*)â
ÂÂiss.rdbuf(&fbuf);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ^
InÂfileÂincludedÂfromÂt.cxx:2:0:
/usr/include/c++/5.3.1/sstream:472:7:Ânote:Âcandidate:Âstd::__cxx11::basic_istringstream<_CharT,Â_Traits,Â_Alloc>::__stringbuf_type*Âstd::__cxx11::basic_istringstream<_CharT,Â_Traits,Â_Alloc>::rdbuf()ÂconstÂ[withÂ_CharTÂ=Âchar;Â_TraitsÂ=Âstd::char_traits<char>;Â_AllocÂ=Âstd::allocator<char>;Âstd::__cxx11::basic_istringstream<_CharT,Â_Traits,Â_Alloc>::__stringbuf_typeÂ=Âstd::__cxx11::basic_stringbuf<char>]
ÂÂÂÂÂÂÂrdbuf()Âconst
ÂÂÂÂÂÂÂ^
/usr/include/c++/5.3.1/sstream:472:7:Ânote:ÂÂÂcandidateÂexpectsÂ0Âarguments,Â1Âprovided

However, I have to a (unnecessary) cast to get it working, like this:
ÂÂÂÂ((istream&)iss).rdbuf(&fbuf);

I'm always intimated by C++ template syntax. I wonder what have I done wrong this time.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]