base class public type (non template and template base class)

H

Hicham Mouline

Hello,

This compiles

#include <iostream>

class Base {
public:
typedef double type;
};

class Derived : public Base {
public:
void f(type t) const {}
};


While this

template <typename T>
class Base {
public:
typedef double type;
};

template <typename T>
class Derived : public Base<T> {
public:
void f(type t) const {} // type has not been declared
};


This templated version requires

template <typename T>
class Derived : public Base<T> {
public:
void f(typename Base<T>::type t) const {}
};


Is g++3.4 standard compliant here? Or is this a g++3.4 restriction?

writing
typename Base<T>::type
is tedious?

I tried to put type in a non template base class B of Base, but in Derived,
I still needed to qualify B::type

rds,
 
V

Victor Bazarov

Hicham said:
This compiles

#include <iostream>

class Base {
public:
typedef double type;
};

class Derived : public Base {
public:
void f(type t) const {}
};


While this

template <typename T>
class Base {
public:
typedef double type;
};

template <typename T>
class Derived : public Base<T> {
public:
void f(type t) const {} // type has not been declared
};


This templated version requires

template <typename T>
class Derived : public Base<T> {
public:
void f(typename Base<T>::type t) const {}
};


Is g++3.4 standard compliant here? Or is this a g++3.4 restriction?

writing
typename Base<T>::type
is tedious?

I tried to put type in a non template base class B of Base, but in Derived,
I still needed to qualify B::type

FAQ section 35. See "dependent name".

V
 

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,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top