basic_streambuf

Discussion in 'C++' started by Fraser Ross, Mar 21, 2008.

  1. Fraser Ross

    Fraser Ross Guest

    template <typename char_tp= char, typename traits_tp=
    std::char_traits<char_tp> >
    class MyStreamBuf : public std::basic_streambuf<char_tp, traits_tp>,
    private noncopyable {

    I defined my streambuf class as above. std::basic_streambuf has a
    public typedef:
    typedef typename traits_type::int_type int_type;

    I have to redeclare the typedef in MyStreamBuf to use int_type without
    any qualification. This seems strange to me. Is it a compiler bug?

    Fraser.



    --
    Posted via a free Usenet account from http://www.teranews.com
     
    Fraser Ross, Mar 21, 2008
    #1
    1. Advertising

  2. Fraser Ross

    gnuyuva Guest

    On Mar 21, 5:19 pm, "Fraser Ross" <> wrote:
    > template <typename char_tp= char, typename traits_tp=
    > std::char_traits<char_tp> >
    > class MyStreamBuf : public std::basic_streambuf<char_tp, traits_tp>,
    > private noncopyable {
    >
    > I defined my streambuf class as above. std::basic_streambuf has a
    > public typedef:
    > typedef typename traits_type::int_type int_type;
    >
    > I have to redeclare the typedef in MyStreamBuf to use int_type without
    > any qualification. This seems strange to me. Is it a compiler bug?


    No, thats the way templates work. The same is true for functions in
    base class also.

    template <typename T>
    struct base
    {
    typedef int int_t;
    void func();
    };

    template <typename T>
    struct derived : public base<T>
    {
    // int_t function(); -> Error.
    typename base<T>::int_t function(); // works fine.

    void call_base_class_func()
    {
    // func(); -> Error;
    base<T>::func();
    }
    };

    But thats not the case if you do such stuff outside template
    definitions.

    void my_global_func()
    {
    // Perfectly fine though you dont have the 'int_t' definition in
    // 'derived' class.
    derived<int>::int_t val;

    // perfectly legal.
    val.func();
    }
     
    gnuyuva, Mar 21, 2008
    #2
    1. Advertising

  3. Fraser Ross

    gnuyuva Guest

    On Mar 21, 5:51 pm, gnuyuva <> wrote:
    > void my_global_func()
    > {
    > // Perfectly fine though you dont have the 'int_t' definition in
    > // 'derived' class.
    > derived<int>::int_t val;
    >
    > // perfectly legal.


    Sorry its:
    derived<int> obj;
    obj.func();

    > val.func();
    >
    > }
     
    gnuyuva, Mar 21, 2008
    #3
    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. Guest
    Replies:
    3
    Views:
    737
    John Harrison
    Aug 8, 2004
  2. Guest
    Replies:
    0
    Views:
    409
    Guest
    Aug 28, 2004
  3. Guest
    Replies:
    1
    Views:
    572
    Jonathan Turkanis
    Aug 29, 2004
  4. Steven T. Hatton

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

    Steven T. Hatton, Jul 3, 2005, in forum: C++
    Replies:
    3
    Views:
    532
    Steven T. Hatton
    Jul 4, 2005
  5. sri
    Replies:
    2
    Views:
    376
    Carl Barron
    Apr 6, 2007
Loading...

Share This Page