Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does it makes sense a virtual template method?

Suppose a construct like this:

class Interface
{
public:
   template <typename T>
   virtual void reportOperationError(T code , std::string message) = 0;
};

i don't understand the use case for this thing, in which case it is useful, and how?

In case you wonder, I haven't seen this code anywhere, just want to understand if this could have some particular use

like image 476
lurscher Avatar asked Jul 10 '11 15:07

lurscher


1 Answers

Templated member functions cannot be virtual... Each instantiation of the function will add another entry to the virtual table, and the compiler will have to go over all of the code in order to create the vtable. Therefore, regardless of it being useful or not, it's just not legal C++.

like image 119
eran Avatar answered Sep 22 '22 09:09

eran