C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

question on the standard regarding templates, inheritance, a

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Thant Tessman
Guest





PostPosted: Fri Jun 24, 2005 6:40 am    Post subject: question on the standard regarding templates, inheritance, a Reply with quote




Someone was trying to compile some code of mine with gcc 3.4.3 (which I
don't have) and running into the following problem. Given a
parameterized base class like so:

template <typename T>
struct Base {
inline void blah() {/*whatever*/}
};

Does a derived class have to qualify the use of "blah" with the base
class name? That is, am I supposed to need to do this:

template <typename T>
struct Derived : Base<T> {
inline void blahBlah() {
Base<T>::blah();
}
};

Or am I supposed to be allowed to merely do this:

template <typename T>
struct Derived : Base<T> {
inline void blahBlah() {
blah();
}
};

gcc 3.4.3 wants the name qualified, but none of the compilers I use do.
Luckily the older compilers don't care if I add the scope
qualifications, but I'm really curious if this is merely a case where
3.4.3 is more standards-conforming, or if it's just being quirky.

Thanks for any info,

-thant


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Alf P. Steinbach
Guest





PostPosted: Fri Jun 24, 2005 8:46 am    Post subject: Re: question on the standard regarding templates, inheritanc Reply with quote



* Thant Tessman:
Quote:

Someone was trying to compile some code of mine with gcc 3.4.3 (which I
don't have) and running into the following problem. Given a
parameterized base class like so:

template <typename T
struct Base {
inline void blah() {/*whatever*/}
};

Does a derived class have to qualify the use of "blah" with the base
class name?

No, but it has to tell the compiler in some way that the function is a
base class member function.


Quote:
That is, am I supposed to need to do this:

template struct Derived : Base inline void blahBlah() {
Base<T>::blah();
}
};

You can do

1) Base<T>::blah();
2) this->blah();
3) using Base<T>::blah; inline void blahBlah(){ blah(); }

The first is Good if you really always want the Base<T> version, also in
derived classes, and Bad if that isn't necessarily what you want and blah()
can be virtual.


Quote:
Or am I supposed to be allowed to merely do this:

template <typename T
struct Derived : Base inline void blahBlah() {
blah();
}
};

No, that shouldn't compile. I think however this was commonly accepted before
standardization of the language. But I'm not sure about that bit of history.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Gene Bushuyev
Guest





PostPosted: Fri Jun 24, 2005 11:11 am    Post subject: Re: question on the standard regarding templates, inheritanc Reply with quote



A short answer: T is a dependent type, Base template will not be looked up,
so you need to use fully qualified name Base<T>::blah() in derived class.

"Thant Tessman" <thant (AT) acm (DOT) org> wrote

Quote:

Someone was trying to compile some code of mine with gcc 3.4.3 (which I
don't have) and running into the following problem. Given a
parameterized base class like so:

template <typename T
struct Base {
inline void blah() {/*whatever*/}
};

Does a derived class have to qualify the use of "blah" with the base
class name? That is, am I supposed to need to do this:

template struct Derived : Base inline void blahBlah() {
Base<T>::blah();
}
};


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.