class scope virtual template functions
Walter Bright
newshound1 at digitalmars.com
Thu May 29 12:36:38 PDT 2008
BCS wrote:
> However in highly limited cases, this is not an issue.
> 1) the template members are enumerations (just build the whole set)
> 2) the function has no parameters (only one version can be built)
> 3) no general form of the template exists, only explicit specializations
> (ditto enum)
> 4) class scope aliases of member templates are used. (instance the
> template and stuff it in as a normal function)
True, but now you have the issue that minor, seemingly innocuous changes
to a template function can have dramatic changes to its behavior. It's a
lot easier to understand "template functions are not virtual" than
"template functions are not virtual except in these rather complex
scenarios."
If you need virtual behavior from a template function, the best way is
to wrap a virtual function call within it.
More information about the Digitalmars-d
mailing list