Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > base class public type (non template and template base class)

Reply
Thread Tools

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

 
 
Hicham Mouline
Guest
Posts: n/a
 
      04-20-2009
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,


 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-20-2009
Hicham Mouline wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
 
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
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSE 4 11-15-2006 02:40 AM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola Microsoft Certification 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd loyola MCSD 3 11-14-2006 05:18 PM
microsoft.public.certification, microsoft.public.cert.exam.mcsa, microsoft.public.cert.exam.mcad, microsoft.public.cert.exam.mcse, microsoft.public.cert.exam.mcsd realexxams@yahoo.com Microsoft Certification 0 05-10-2006 02:35 PM
microsoft.public.dotnet.faqs,microsoft.public.dotnet.framework,microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb Charles A. Lackman ASP .Net 1 12-08-2004 07:08 PM



Advertisments