Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > basic_streambuf

Reply
Thread Tools

basic_streambuf

 
 
Fraser Ross
Guest
Posts: n/a
 
      03-21-2008
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

 
Reply With Quote
 
 
 
 
gnuyuva
Guest
Posts: n/a
 
      03-21-2008
On Mar 21, 5:19 pm, "Fraser Ross" <(E-Mail Removed)> 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();
}
 
Reply With Quote
 
 
 
 
gnuyuva
Guest
Posts: n/a
 
      03-21-2008
On Mar 21, 5:51 pm, gnuyuva <(E-Mail Removed)> 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();
>
> }


 
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