templates, typename, and basic_streambuf method return type problems

C

Christopher

I am trying to derive from the basic_streambuf, following an example in my
book and am getting the following error:

1>loggerstreambuffer.hxx(32) : error C2440: 'return' : cannot convert from
'std::char_traits<char>::int_type (__cdecl *)(void)' to 'int'

I do not understand why it wants an int instead of an int_type, especially
after looking over the basic_streambuf header. Is this some implementation
specific thing?

Admitadly I do not understand the difference between a typdef and a typename
and a typedef typename. I know what a typedef is just fine, but never have
used a typename. I would think my class would inherit what an int_type is
from the basic_streambuf.

I also have no idea what the __CLR_OR_THIS_CALL macro is doing in my
basic_streambuf implementation. I suspect its a MS specific thing and hope
its not the problem. It appears to be doing the __cdecl.

code:

#ifndef LOGGERSTREAMBUFFER_HXX
#define LOGGERSTREAMBUFFER_HXX

#include <iostream>

namespace cpisz_common_lib
{

//----------------------------------------------------------------------------------------------------------------------
template <class charT, class traits >
class LoggerStreamBuffer : public std::basic_streambuf<charT, traits>
{
public:
/*
typedef charT char_type;
typedef traits traits_type;

typedef typename traits::int_type int_type;
typedef typename traits::pos_type pos_type;
typedef typename traits::eek:ff_type off_type;
*/
LoggerStreamBuffer()
:
m_takeFromBuffer(false)
{
}

protected:

int_type overflow(int_type c = traits_type::eof())
{
return traits_type::eof;
}

int_type uflow()
{
return traits_type::eof;
}

int_type underflow()
{
return traits_type::eof;
}

int_type pbackfail(int_type c)
{
return traits_type::eof;
}

private:

/** Prevents copy construction */
LoggerStreamBuffer(const LoggerStreamBuffer &);

/** Prevents assignment */
LoggerStreamBuffer & operator =(const LoggerStreamBuffer &);

/** Internal buffer */
char_type m_charBuffer;

bool m_takeFromBuffer;
};

}// namespace cpisz_common_lib

#endif


instantiation:

//-----
// Test the LoggerStreamBuffer
LoggerStreamBuffer<char, std::char_traits<char> > buffer;


Copy paste from my basic_streambuf header:

[snip]

template<class _Elem, class _Traits>
class basic_streambuf
{

[snip]

virtual int_type __CLR_OR_THIS_CALL overflow(int_type = _Traits::eof())
{
// put a character to stream (always fail)
return (_Traits::eof());
}

[snip]

public:

typedef basic_streambuf<_Elem, _Traits> _Myt;
typedef _Elem char_type;
typedef _Traits traits_type;

[snip]

typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::eek:ff_type off_type;
 
C

Christopher Pisz

Christopher said:
I am trying to derive from the basic_streambuf, following an example in my
book and am getting the following error:

1>loggerstreambuffer.hxx(32) : error C2440: 'return' : cannot convert from
'std::char_traits<char>::int_type (__cdecl *)(void)' to 'int'
[snip]

I had a typo. traits_type::eof should be traits_type::eof()
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top