1

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.

Community
  • 1
  • 1
Badder
  • 35
  • 1
  • 3
  • 5
    Looks like it should work... Try if `BaseQNativeWindow::template findChildren< QWidget* >()` solves it – K-ballo Nov 13 '12 at 16:30
  • 1
    [this post](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords/613132#613132) might help. – juanchopanza Nov 13 '12 at 16:31
  • Indeed adding "template" solves it, thank you. Need to brush up my template knowledge. I'll accept your answer if you create it :) . – Badder Nov 13 '12 at 16:41

1 Answers1

5

You have to say:

BaseQNativeWindow::template findChildren< QWidget * >()
//                 ^^^^^^^^

Since findChildren is a dependent name, its meaning must be disambiguated.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084