[英]Can specializations of a template function be virtual?
Something like, for example, 例如,像
class A {
template<typename T> T DoStuff();
template<> virtual int DoStuff<int>() = 0;
};
Visual Studio 2010 says no, but I get a funny feeling that I simply messed up the syntax. Visual Studio 2010说没有,但我觉得很简单,我只是搞砸了语法。 Can explicit full specializations of a member function template be virtual?
成员函数模板的显式完全特化是否可以是虚拟的?
Explicit specializations aren't legal within a class. 明确的专业化在一个类中是不合法的。 Even if you could make it a partial specialization you would still run into the "templates can't be virtual" problem.
即使你可以使它部分特化,你仍然会遇到“模板不能虚拟”的问题。
n3290, § 14.5.2 states: n3290,§14.5.2规定:
A member function template shall not be virtual.
成员函数模板不应是虚拟的。
And gives this example: 并给出了这个例子:
template <class T> struct AA {
template <class C> virtual void g(C); // error
virtual void f(); // OK
};
Before going on to state that member function templates do not count for virtual overrides too. 在继续说明成员函数模板也不计入虚拟覆盖之前。
According to C++98 Standard member function template shall not be virtual. 根据C ++ 98标准,成员函数模板不应是虚拟的。 http://www.kuzbass.ru:8086/docs/isocpp/template.html .
http://www.kuzbass.ru:8086/docs/isocpp/template.html 。
-3- A member function template shall not be virtual.
-3-成员函数模板不应是虚拟的。 [Example:
[例:
template <class T> struct AA { template <class C> virtual void g(C); // error virtual void f(); // OK };
您可以通过使用常规非模板虚函数重载功能模板来获得类似的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.