Imagine this code:
class foo
{
foo fff;
int m_id;
f & work() { return fff; }
};
typedef foo f;
This will compile fine, but this one:
class QX_SERVICE_DLL_EXPORT Code
{
public:
Code() : m_Id(0) { ; }
virtual ~Code() { ; }
inline long id() const { return m_Id; }
inline void setId(long id) { m_Id = id; }
inline const QString & code() const { return m_Code; }
inline void setCode(const QString & code) { m_Code = code; }
inline const QString & name() const { return m_Name; }
inline void setName(const QString & name) { m_Name = name; }
inline const QSharedPointer<Code> & parent() const { return m_Parent; }
inline void setParent(const QSharedPointer<Code> & parent) { m_Parent = parent; }
CodeList & children() { return m_Children; }
private:
long m_Id;
QString m_Code;
QString m_Name;
QSharedPointer<Code> m_Parent;
qx::QxCollection<long, QSharedPointer<Code>> m_Children;
friend void registerOrm(qx::QxClass<Code> & t);
};
typedef qx::QxCollection<long, QSharedPointer<Code> > CodeList;
What’s the difference? Why it doesn’t work with class Code and works with class foo?
Sorry for my broken English 🙂
I’m getting several errors, one of them is “Missing type specifier – int assumed” at CodeList & children() { return m_Children; }
I assume that typedef CodeList is not processed by the compiler when it is processing CodeList members in Code class, but I don’t understand why it is working for the first case. If I write the following:
class Code;
typedef qx::QxCollection<long, QSharedPointer<Code>> CodeList;
class QX_SERVICE_DLL_EXPORT Code
{
...
Then everything works fine.
BTW, I’m using MSVC 2010 compiler
This is wrong:
You might mean:
I am pretty sure that the compiler should have provided an error message in that line of code, so my recommendation is read the error messages. If it hasn’t, then you might not have included the header where the typedef is declared… include it. Additionally in the header where it is declared, you cannot use it before it has been declared (C++ process top to bottom, or kind of, in most cases at least…)