This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
istringstream.rdbuf with custom streambuf does not compile
- From: ææé <ssawgift at 163 dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 6 May 2016 20:40:03 +0800 (CST)
- Subject: istringstream.rdbuf with custom streambuf does not compile
- Authentication-results: sourceware.org; auth=none
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.