Bad*_*der 1 c++ qt templates gcc4
可能重复:
在"模板化基类"中调用模板方法时出错
以下代码使用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();
}
}
};
Run Code Online (Sandbox Code Playgroud)
这就是gcc抱怨的:
error: expected primary-expression before ‘*’ token
error: expected primary-expression before ‘>’ token
error: expected primary-expression before ‘)’ token
Run Code Online (Sandbox Code Playgroud)
findChildren是一种BaseQNativeWindow必须提供的模板化方法.似乎gcc假设findChildren在知道什么类型之前不是模板BaseQNativeWiindow.有谁能解释一下?
谢谢.
你不得不说:
BaseQNativeWindow::template findChildren< QWidget * >()
// ^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
由于findChildren是从属名称,因此必须消除其含义.