Hi,

I'm facing a compilation problem : I don't have it with visual studio compiler, but when I try to compile the same code using QtCreator with Linux (and apparently reproduced on Mac), an error appears.

header1.h code :
Qt Code:
  1. #ifndef _MY_CLASS1_H_
  2. #define _MY_CLASS1_H_
  3.  
  4. #include <QObject>
  5.  
  6. class MyClass1 : public QObject
  7. {
  8. Q_OBJECT
  9.  
  10. public :
  11.  
  12. MyClass1(QObject *parent=0) ;
  13. virtual ~MyClass1(void) ;
  14. } ;
  15.  
  16. #endif // _MY_CLASS1_H_
To copy to clipboard, switch view to plain text mode 

class1.cpp code :
Qt Code:
  1. #include "header1.h"
  2. #include "header2.h"
  3.  
  4. MyClass1::MyClass1(QObject *parent)
  5. : QObject(parent)
  6. {
  7. }
  8.  
  9.  
  10. MyClass1::~MyClass1()
  11. {
  12. }
To copy to clipboard, switch view to plain text mode 


header2.h code :

Qt Code:
  1. #ifndef _MY_CLASS2_H_
  2. #define _MY_CLASS2_H_
  3.  
  4. #include <QObject>
  5. #include <QList>
  6.  
  7. class MyClass2 : public QObject
  8. {
  9. Q_OBJECT
  10.  
  11. public :
  12.  
  13. MyClass2(QObject *parent=0) ;
  14. virtual ~MyClass2(void) ;
  15.  
  16. template<typename T>
  17. QList<T*> listOfTypedObjects(void) const ;
  18. } ;
  19.  
  20. template<typename T>
  21. QList<T*>
  22. MyClass2::listOfTypedObjects(void) const
  23. {
  24. QList<T*> result1 ;
  25. QList<T*> result2 ;
  26.  
  27. QList<T*>::const_iterator it ;
  28. for(it=result1.begin(); it!=result1.end(); it++)
  29. result2.push_back(*it) ;
  30.  
  31. return result2 ;
  32. }
  33. #endif // _MY_CLASS2_H_
To copy to clipboard, switch view to plain text mode 

class2.cpp code :
Qt Code:
  1. #include "header2.h"
  2.  
  3. MyClass2::MyClass2(QObject *parent)
  4. : QObject(parent)
  5. {
  6. }
  7.  
  8.  
  9. MyClass2::~MyClass2()
  10. {
  11. }
To copy to clipboard, switch view to plain text mode 


The error points to MyClass2::listOfTypedObjects method body - and more specifically to the iterator declaration - and tells something like :

line 27 : expected ';' before it
as if It did not recognize QList<T*>::const_iterator definition.

I attached a small example reproducing the problem.
templates.zip

Any idea what I'm missing ?