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 

virtual member function templates

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
dj
Guest





PostPosted: Thu Sep 14, 2006 9:10 am    Post subject: virtual member function templates Reply with quote



I somehow understand why member function templates cannot be virtual,
but my question is how I could achieve something similar to this:

class A {
public:
template<typename T> virtual f() = 0;
}

class B : public A {
public:
template<typename T> f();
}

class C : public A {
public:
template<typename T> f();
}

That is, I would like to force subclasses to implement a templated
member function f.
Back to top
werasm
Guest





PostPosted: Fri Sep 15, 2006 9:10 am    Post subject: Re: virtual member function templates Reply with quote



dj wrote:
Quote:
This code really does the thing, thank you. I agree it is very weird,
though. Especially the call "derived->template f<T>();" is something new
to me. I tried and it works as "derived->f<T>();", too.

The other way is technically correct. If the compiler compiles
derived->f<T>(), which VC++7.1 does do, its not iaw. standard. The
template syntax is for the compiler to discern that < is not a
relational operator, I think. Someone else can perhaps comment (my time
is limited right now).

Regards,

Werner
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) 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.