虚拟模板?
我试图声明一个抽象类,但只是模板化虚函数的行为就会让编译器抱怨。这通常是如何实现的?例如,在我的头文件中,
virtual SpecialList<Point> *getPoints() const;
编译器声明“ISO C++ 禁止声明没有类型的‘SpecialList’”。
编辑 Point 和 SpecialList 都包含在此类的定义中。作为一个更详细的例子,
// SomeClass.h
#include "SpecialList.h"
#include "Point.h"
class SomeClass
{
public:
SomeClass();
virtual SpecialList<Point> *getPoints() const;
//snip
};
仍然没有解决..
I am trying to declare an abstract class, but just the act of templating a virtual function makes the compiler complain. How is this normally accomplished? For example, in my header file I have:
virtual SpecialList<Point> *getPoints() const;
To which the compiler states "ISO C++ forbids declaration of 'SpecialList' with no type."
edit
Both Point and SpecialList are included in the definition of this class. As a more verbose example,
// SomeClass.h
#include "SpecialList.h"
#include "Point.h"
class SomeClass
{
public:
SomeClass();
virtual SpecialList<Point> *getPoints() const;
//snip
};
Still not solved..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说效果很好。确保在使用“SpecialList”和“Point”之前已定义它们。
Works fine for me. Make sure that 'SpecialList' and 'Point' are defined before you use them.
看起来您在使用它之前还没有定义
Point
。在抽象类之前定义
Point
,或者包含定义它的头文件!--
或者,如果您尝试定义虚拟函数模板,如下所示:
那么这是不可能的。不允许使用虚函数模板!
It looks like you haven't defined
Point
before you're using it.Define
Point
before the abstract class, or include the header file in which it's defined!--
Or in case if you're trying to define virtual function template, something like this:
Then it's not possible. virtual function template is not allowed!
检查您是否#included SpecialList 和 Point 类声明或前向声明或类型定义它。
Check if you #included SpecialList and Point class declarations or forward-declarated or typedefed it.