1
可能重复:
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似乎认为findChildren
甚至在知道BaseQNativeWiindow
是什么类型之前不是模板。任何人都可以解释吗?
谢谢。
看起来它应该工作...尝试如果'BaseQNativeWindow :: template findChildren < QWidget* >()'解决它 –
[this post](http://stackoverflow.com/questions/610245/where-and-why-do -i-have-to-put-the-template-and-typename-keywords/613132#613132)可能会有所帮助。 – juanchopanza
确实添加“模板”解决它,谢谢。需要刷新我的模板知识。如果你创建它,我会接受你的答案:)。 – Badder