Possible Duplicate:
Error calling template method in “templated-base-class”
The following code compiles with MSVC10 but not with 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();
}
}
};
This is what gcc complains about:
error: expected primary-expression before ‘*’ token
error: expected primary-expression before ‘>’ token
error: expected primary-expression before ‘)’ token
findChildren
is a templated method that BaseQNativeWindow
must provide. It seems that gcc assumes that findChildren
is not a template even before knowing what type BaseQNativeWiindow
is. Can anyone explain this?
Thanks.
You have to say:
BaseQNativeWindow::template findChildren< QWidget * >()
// ^^^^^^^^
Since findChildren
is a dependent name, its meaning must be disambiguated.