Click to See Complete Forum and Search --> : Virtual Template Function
Lil'Hasher
February 21st, 2003, 11:35 PM
Hello,
I was wondering if it's possible to have a virtual template function. That is have a class, that has as one of its member functions a templated function that is also pure virtual.
ie.
Class A {
template <class T>
virtual int foo ( T & param ) = 0;
}
// class B is dervied from class A
Class B : public class A {
template <class T>
int foo (T & param) {
// implement foo...
}
}
When I arrange my code like this I get all sorts of errors, indicating that this is not allowed. Is there something i'm doing wrong? I dont see what the problem would be....any help at all would be appreciated!
thanks
Lil' Hash
PaulWendt
February 22nd, 2003, 10:10 AM
As far as I know, there cannot be templatized virtual member
functions.
--Paul
SeventhStar
February 23rd, 2003, 05:40 AM
well i tried to do it and i think this error explains it all
D:\experiments\exper\test.cpp(7) : error C2898: 'int __thiscall a::af(T)' : member function templates cannot be virtual
PaulWendt
February 23rd, 2003, 06:11 AM
Originally posted by SeventhStar
well i tried to do it and i think this error explains it all
D:\experiments\exper\test.cpp(7) : error C2898: 'int __thiscall a::af(T)' : member function templates cannot be virtual
In this example, you happen to be correct ... but don't rely upon
Microsoft's compiler when testing Standard-conformance in the
future; they've been known to be missing features in the past :)
Graham
February 23rd, 2003, 06:37 AM
Think about it for a while: how could you make a templated virtual function? What's its signature? How many vtable entries do you reserve? How would you distinguish between an override/hide and an overload?
KevinHall
February 24th, 2003, 10:30 AM
I believe it is not possible -- mainly for the reasons Graham pointed out.
BTW, even g++ won't compile the code -- it is not just a MS-specific problem!
- Kevin
PaulWendt
February 24th, 2003, 12:23 PM
Originally posted by KevinHall
I believe it is not possible -- mainly for the reasons Graham pointed out.
BTW, even g++ won't compile the code -- it is not just a MS-specific problem!
- Kevin
I hope I didn't imply that I thought it was.... I just meant that
something not working on a Microsoft compiler isn't usually good
enough reason to say "the standard doesn't allow this". Heck,
ANY one compiler isn't really good enough reason.
KevinHall
February 24th, 2003, 12:44 PM
Paul,
No, I understood what you were saying. And I know that MS doesn't comply completely with the ANSI standard -- especially MSVC 6.0. I was just letting others know that g++ doesn't compile it either (perhaps I should have left that exclamation point off at the end. ;) ). Personally, I think your responses are accurate and full of useful information. I hope there are no hard feelings!
- Kevin
PaulWendt
February 24th, 2003, 02:48 PM
Originally posted by KevinHall
Paul,
No, I understood what you were saying. And I know that MS doesn't comply completely with the ANSI standard -- especially MSVC 6.0. I was just letting others know that g++ doesn't compile it either (perhaps I should have left that exclamation point off at the end. ;) ). Personally, I think your responses are accurate and full of useful information. I hope there are no hard feelings!
- Kevin
Aw hey, not at all, my fellow poster. I didn't even mean to come
across as being defensive, but reading my post on my own ... it
definitely would appear that way.
Is it just me or does it seem like computer people don't know how
to communicate properly? :) Bah, it's probably just me :)
--Paul
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.