Originally Posted by
NewLegend
The least number of lines and more accurate.
The number of lines of code is not that relevant, consider the two examples:
struct one {
};
struct one {
QString a;
QString b;
};
To copy to clipboard, switch view to plain text mode
struct two {
void setA
(const QString &a
) { m_a
= a;
} void setB
(const QString &b
) { m_b
= b;
} const QString &a
() const { return m_a;
} const QString &b
() const { return m_b;
} private:
};
struct two {
two(const QString &_a, const QString &_b) : m_a(_a), m_b(_b){}
void setA(const QString &a) { m_a = a; }
void setB(const QString &b) { m_b = b; }
const QString &a() const { return m_a; }
const QString &b() const { return m_b; }
private:
QString m_a;
QString m_b;
};
To copy to clipboard, switch view to plain text mode
Which is better? From what point of view? And how about this one?
three_private
(const three_private
&other
) : QSharedData(other
), a
(other.
a), b
(other.
b){}};
class three {
public:
three() : d(new three_private){}
three(const three &other) : d(other.d){}
void setA
(const QString &a
) { d
->a
= a;
} void setB
(const QString &b
) { d
->b
= b;
} const QString &a
() const { return d
->a;
} const QString &b
() const { return d
->b;
} private:
QSharedDataPointer<three_private> d;
};
struct three_private : public QSharedData {
QString a;
QString b;
three_private() : QSharedData(){}
three_private(const three_private &other) : QSharedData(other), a(other.a), b(other.b){}
};
class three {
public:
three() : d(new three_private){}
three(const three &other) : d(other.d){}
void setA(const QString &a) { d->a = a; }
void setB(const QString &b) { d->b = b; }
const QString &a() const { return d->a; }
const QString &b() const { return d->b; }
private:
QSharedDataPointer<three_private> d;
};
To copy to clipboard, switch view to plain text mode
Which is fastest? Which is least error prone? Which is easiest to extend, i.e. by forcing "b" to be lowercase alphanumeric characters only?
There is difficulty in building data structures with qt4. If you use inheritance in data structures.
You can use C structures in Qt-based code as well, if you want and you like to inflict pain on yourself while programming
Edit: Oh, for completeness regarding your code, there is QLinkedList.
Bookmarks