templates, typename, and basic_streambuf method return type problems

Discussion in 'C++' started by Christopher, Jan 29, 2008.

  1. Christopher

    Christopher Guest

    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;
     
    Christopher, Jan 29, 2008
    #1
    1. Advertising

  2. "Christopher" <> wrote in message
    news:479ecd21$0$30715$...
    >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()
     
    Christopher Pisz, Jan 29, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven T. Hatton

    I/O std::basic_streambuf put and get areas?

    Steven T. Hatton, Jul 3, 2005, in forum: C++
    Replies:
    3
    Views:
    530
    Steven T. Hatton
    Jul 4, 2005
  2. Generic Usenet Account
    Replies:
    3
    Views:
    845
    Generic Usenet Account
    Jul 14, 2005
  3. Victor Bazarov
    Replies:
    6
    Views:
    320
  4. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    369
    Rolf Magnus
    Mar 14, 2006
  5. Sanil
    Replies:
    2
    Views:
    4,822
    James Kanze
    Dec 14, 2007
Loading...

Share This Page