Reputation: 1486
I have just started with C++ Qt and I wrote the following .h file: The .cpp file contains only empty constructors and destructors.
#include <QList>
class XML_Files
{
public:
XML_Files();
~XML_Files();
protected:
QList<Myclass> m_Xmls;
};
class Myclass
{
public:
Myclass();
~Myclass();
protected:
int a;
};
but I keep getting the following errors:
error C2065: 'Myclass': undeclared identifier
error C2923: 'QList': 'Myclass' is not a valid template type argument for parameter 'T'
What do I have to do to declare a Qlist
with my own data type?
Upvotes: 0
Views: 881
Reputation: 5439
The easy way to fix this, is to turn the order of both classes. However there is a second solution, if this is not desired or possible:
You may declare Myclass
before defining it. Then compilation will succeed.
#include <QList>
class Myclass;
class XML_Files
{
public:
XML_Files();
~XML_Files();
protected:
QList<Myclass> m_Xmls;
};
class Myclass
{
// ...
};
Upvotes: 1
Reputation: 180965
You can't use the name MyClass
until the compiler knows about it. Since you do not declare MyClass
until after XML_Files
you cannot use it's name in XML_Files
.
The simplest solution here is to just change the order of the declarations and declare MyClass
before XML_Files
.
Upvotes: 3