 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
dj Guest
|
Posted: Thu Sep 14, 2006 9:10 am Post subject: virtual member function templates |
|
|
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
|
Posted: Fri Sep 15, 2006 9:10 am Post subject: Re: virtual member function templates |
|
|
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 |
|
 |
|
|
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
|
|