Boost logo

Boost :

Subject: [boost] Request For a feature - Templated virtual functions
From: Gokulakannan Somasundaram (gokul007_at_[hidden])
Date: 2009-02-11 13:27:46


Hi All,
         As you all know, there are situations, wherein the virtual function
usage can be replaced with templates. But virtual functions can never be
used with templates, since all the instantiations have to be tracked to form
the virtual function table. But we can ask the user to provide a typelist of
classes, that would probably be used with the virtual template function. I
think this would solve this issue for most of the cases.

Analyzing the instances where this would be useful -
a) Any virtual function, which might need different types of arguments (not
related to the inheritance hierarchy)
b) I have a multi-method design pattern, where in i need more than one
run-time resolution through the virtual functions. But sometimes, i might
know one of the actual derived classes involved, with which i can avoid one
virtual function call.

        I am not an expert in C++, but one way of achieving this would be to
manually have a hash table with all the necessary function pointers for each
class in the base class hierarchy and one such set for each of the classes
mentioned in the typelist.

        Waiting for your feedback.

Thanks in advance,
Gokul.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk