M
marwie
Hi,
I'm trying to derive my own stream class from std::basic_istream and
I'm having problems getting operator>> to work. Consider the following
little program:
#include <iostream>
#include <istream>
#include <bits/char_traits.h>
template<typename _CharT, typename _Traits>
class myistream : public std::basic_istream<_CharT, _Traits>
{
// constructor
myistream() : std::basic_istream<_CharT, _Traits>(NULL) { }
// destructor
~myistream() { }
};
int main(int argc, char** argv)
{
myistream<char, std::char_traits<char> > is();
char c;
is >> c;
std::cout << c << std::endl;
}
Compiling it I get the following error:
test.cpp: In function 'int main(int, char**)':
test.cpp:22: error: invalid operands of types 'myistream<char,
std::char_traits<char> > ()()' and 'char' to binary
'operator>>'
I've looked at the fstream header to see how basic_ifstream is derived
from basic_istream and to me it looks like my little test program does
essentially the same. Any Ideas?
Thanks in advance,
Martin.
I'm trying to derive my own stream class from std::basic_istream and
I'm having problems getting operator>> to work. Consider the following
little program:
#include <iostream>
#include <istream>
#include <bits/char_traits.h>
template<typename _CharT, typename _Traits>
class myistream : public std::basic_istream<_CharT, _Traits>
{
// constructor
myistream() : std::basic_istream<_CharT, _Traits>(NULL) { }
// destructor
~myistream() { }
};
int main(int argc, char** argv)
{
myistream<char, std::char_traits<char> > is();
char c;
is >> c;
std::cout << c << std::endl;
}
Compiling it I get the following error:
test.cpp: In function 'int main(int, char**)':
test.cpp:22: error: invalid operands of types 'myistream<char,
std::char_traits<char> > ()()' and 'char' to binary
'operator>>'
I've looked at the fstream header to see how basic_ifstream is derived
from basic_istream and to me it looks like my little test program does
essentially the same. Any Ideas?
Thanks in advance,
Martin.