【发布时间】:2012-11-13 16:28:28
【问题描述】:
可能重复:
Error calling template method in “templated-base-class”
以下代码使用 MSVC10 编译,但不使用 gcc 4.2.1:
template<class BaseQNativeWindow>
class NativeWindow : public BaseQNativeWindow
{
public:
NativeWindow(AIPanelPlatformWindow handle) : BaseQNativeWindow(handle)
{}
protected:
virtual void closeEvent(QCloseEvent *e)
{
QList<QWidget *> childrenList;
childrenList = BaseQNativeWindow::findChildren< QWidget * >(); // GCC ERROR
foreach(QWidget *child, childrenList)
{
child->close();
}
}
};
这就是 gcc 抱怨的:
error: expected primary-expression before ‘*’ token
error: expected primary-expression before ‘>’ token
error: expected primary-expression before ‘)’ token
findChildren 是BaseQNativeWindow 必须提供的模板化方法。似乎 gcc 甚至在知道 BaseQNativeWiindow 是什么类型之前就假定 findChildren 不是模板。谁能解释一下?
谢谢。
【问题讨论】:
-
看起来应该可以了...试试
BaseQNativeWindow::template findChildren< QWidget* >()是否解决了它 -
this post 可能会有所帮助。
-
确实添加“模板”解决了它,谢谢。需要复习一下我的模板知识。如果您创建它,我会接受您的回答:)。