Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > templates, typename, and basic_streambuf method return type problems

Reply
Thread Tools

templates, typename, and basic_streambuf method return type problems

 
 
Christopher
Guest
Posts: n/a
 
      01-29-2008
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:os_type pos_type;
typedef typename traits: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:os_type pos_type;
typedef typename _Traits:ff_type off_type;

 
Reply With Quote
 
 
 
 
Christopher Pisz
Guest
Posts: n/a
 
      01-29-2008

"Christopher" <(E-Mail Removed)> wrote in message
news:479ecd21$0$30715$(E-Mail Removed)...
>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()


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
basic_streambuf question sri C++ 2 04-06-2007 01:37 AM
I/O std::basic_streambuf put and get areas? Steven T. Hatton C++ 3 07-03-2005 11:03 PM
Unbuffered basic_streambuf Implementation C++ 1 08-29-2004 04:38 PM
Unbuffered basic_streambuf C++ 0 08-28-2004 10:43 AM
Deriving from std::basic_streambuf C++ 3 08-08-2004 07:40 AM



Advertisments