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 :
#ifndef _MY_CLASS1_H_
#define _MY_CLASS1_H_
#include <QObject>
{
Q_OBJECT
public :
virtual ~MyClass1(void) ;
} ;
#endif // _MY_CLASS1_H_
#ifndef _MY_CLASS1_H_
#define _MY_CLASS1_H_
#include <QObject>
class MyClass1 : public QObject
{
Q_OBJECT
public :
MyClass1(QObject *parent=0) ;
virtual ~MyClass1(void) ;
} ;
#endif // _MY_CLASS1_H_
To copy to clipboard, switch view to plain text mode
class1.cpp code :
#include "header1.h"
#include "header2.h"
MyClass1
::MyClass1(QObject *parent
){
}
MyClass1::~MyClass1()
{
}
#include "header1.h"
#include "header2.h"
MyClass1::MyClass1(QObject *parent)
: QObject(parent)
{
}
MyClass1::~MyClass1()
{
}
To copy to clipboard, switch view to plain text mode
header2.h code :
#ifndef _MY_CLASS2_H_
#define _MY_CLASS2_H_
#include <QObject>
#include <QList>
{
Q_OBJECT
public :
virtual ~MyClass2(void) ;
template<typename T>
QList<T*> listOfTypedObjects(void) const ;
} ;
template<typename T>
QList<T*>
MyClass2::listOfTypedObjects(void) const
{
QList<T*> result1 ;
QList<T*> result2 ;
QList<T*>::const_iterator it ;
for(it=result1.begin(); it!=result1.end(); it++)
result2.push_back(*it) ;
return result2 ;
}
#endif // _MY_CLASS2_H_
#ifndef _MY_CLASS2_H_
#define _MY_CLASS2_H_
#include <QObject>
#include <QList>
class MyClass2 : public QObject
{
Q_OBJECT
public :
MyClass2(QObject *parent=0) ;
virtual ~MyClass2(void) ;
template<typename T>
QList<T*> listOfTypedObjects(void) const ;
} ;
template<typename T>
QList<T*>
MyClass2::listOfTypedObjects(void) const
{
QList<T*> result1 ;
QList<T*> result2 ;
QList<T*>::const_iterator it ;
for(it=result1.begin(); it!=result1.end(); it++)
result2.push_back(*it) ;
return result2 ;
}
#endif // _MY_CLASS2_H_
To copy to clipboard, switch view to plain text mode
class2.cpp code :
#include "header2.h"
MyClass2
::MyClass2(QObject *parent
){
}
MyClass2::~MyClass2()
{
}
#include "header2.h"
MyClass2::MyClass2(QObject *parent)
: QObject(parent)
{
}
MyClass2::~MyClass2()
{
}
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 ?
Bookmarks