custom istream class

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.
 
A

Adrian

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();

The compiler thinks your are declaring a function named 'is' that returns a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top