basic_streambuf

F

Fraser Ross

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.
 
G

gnuyuva

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();
}
 
G

gnuyuva

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:
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top