Trouble with class template...newbie question

F

fjansen

During the compile of one of our programs with g++ 3.4.6::

/nethome/fjansen/usr/../usr/src/vdevd/src/services/
basic_TstampOstreamBuf.h:69: error: there are no arguments to `epptr'
that depend on a template parameter, so a declaration of `epptr' must
be available

and lots more messages to the same tune as above.

The particular piece of code that this refers to is the following:

template <class charT, class traits = std::char_traits<charT> >
class basic_TstampOstreamBuf : public std::basic_streambuf<charT,
traits> {
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;

/**
* <p>Create a timestamped output stream buffer.
* </p>
*/
basic_TstampOstreamBuf( std::basic_streambuf<charT, traits> &
itsOstreamBuf )
: iWroteTimestamp( false ),
myOstreamBuf( itsOstreamBuf )
{
setp( myBuffer, myBuffer + OurBufferSize );
}

/**
* Destroy a timestamped output stream buffer.
*/
virtual ~basic_TstampOstreamBuf() {
sync();
}

protected:
/**
*
*/
virtual streamsize xsputn( const char_type *s, streamsize n ) {
streamsize remainder = n;
int_type result = traits_type::not_eof( traits_type::eof() );
while ((remainder > 0) &&
!(traits_type::eq_int_type( result, traits_type::eof() ))) {
streamsize space = epptr() - pptr();
streamsize count = std::min( remainder, space );
std::memcpy( pptr(), s, count * sizeof( char_type ) );
remainder -= count;
s += count;
pbump( count );
assert( pptr() <= epptr() );
if (pptr() == epptr()) {
result = overflow();
}
}
return (n - remainder);
}

This code looks to use the basic_streambuf class template, but it
appears that the declarations for epptr and others is not picked up
correctly.

Any hints would be much appreciated.

Thanks,

Frank
 
V

Victor Bazarov

During the compile of one of our programs with g++ 3.4.6::

/nethome/fjansen/usr/../usr/src/vdevd/src/services/
basic_TstampOstreamBuf.h:69: error: there are no arguments to `epptr'
that depend on a template parameter, so a declaration of `epptr' must
be available

and lots more messages to the same tune as above.

The particular piece of code that this refers to is the following:

template <class charT, class traits = std::char_traits<charT> >
class basic_TstampOstreamBuf : public std::basic_streambuf<charT,
traits> {
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;

/**
* <p>Create a timestamped output stream buffer.
* </p>
*/

myOstreamBuf( itsOstreamBuf )
{
setp( myBuffer, myBuffer + OurBufferSize );
}

/**
* Destroy a timestamped output stream buffer.
*/
virtual ~basic_TstampOstreamBuf() {
sync();
}

protected:
/**
*
*/
virtual streamsize xsputn( const char_type *s, streamsize n ) {
streamsize remainder = n;
int_type result = traits_type::not_eof( traits_type::eof() );
while ((remainder > 0) &&
!(traits_type::eq_int_type( result, traits_type::eof() ))) {
streamsize space = epptr() - pptr();
streamsize count = std::min( remainder, space );
std::memcpy( pptr(), s, count * sizeof( char_type ) );
remainder -= count;
s += count;
pbump( count );
assert( pptr() <= epptr() );
if (pptr() == epptr()) {
result = overflow();
}
}
return (n - remainder);
}

This code looks to use the basic_streambuf class template, but it
appears that the declarations for epptr and others is not picked up
correctly.

Any hints would be much appreciated.

If 'epptr' is a member of the base class, try prepending it with
"this->":

space = this->epptr() - this->pptr();

Or just add 'using' to the basic_TstampOstreamBuf class template
definition:

using std::basic_streambuf<charT,traits>::epptr;
using std::basic_streambuf<charT,traits>::pptr;
...

V
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top