S
Svenn Are Bjerkem
Hi Forum,
I am not very much experienced with c++, but I have unfortunately
programmed a lot of c and have a problem understanding the purpose of
defining a struct in the private part of a class. I am looking at the
example code for Interviews in the Qt-4 example code, which
unfortunately hasn't been documented yet.
http://doc.trolltech.com/4.2/demos-interview.html
The part of the code in model.h I don't really understand look like
this:
private:
struct Node
{
Node(Node *parent = 0) : parent(parent), children(0) {}
~Node() { delete children; }
Node *parent;
QVector<Node> *children;
};
Node *node(int row, Node *parent) const;
Node *parent(Node *child) const;
int row(Node *node) const;
int rc, cc;
QVector<Node> *tree;
};
I guess there is a rationale behind doing it this way, but I haven't
found anything like this in the c++ book I have, and a search on
google mostly explain the difference between struct and class and not
how to use a struct like this example. Wouldn't normally Node be
defined as a class on its own? What is the advantage of doing things
this way? Was my google search too lax so that I missed a FAQ
somewhere?
Kind regards,
I am not very much experienced with c++, but I have unfortunately
programmed a lot of c and have a problem understanding the purpose of
defining a struct in the private part of a class. I am looking at the
example code for Interviews in the Qt-4 example code, which
unfortunately hasn't been documented yet.
http://doc.trolltech.com/4.2/demos-interview.html
The part of the code in model.h I don't really understand look like
this:
private:
struct Node
{
Node(Node *parent = 0) : parent(parent), children(0) {}
~Node() { delete children; }
Node *parent;
QVector<Node> *children;
};
Node *node(int row, Node *parent) const;
Node *parent(Node *child) const;
int row(Node *node) const;
int rc, cc;
QVector<Node> *tree;
};
I guess there is a rationale behind doing it this way, but I haven't
found anything like this in the c++ book I have, and a search on
google mostly explain the difference between struct and class and not
how to use a struct like this example. Wouldn't normally Node be
defined as a class on its own? What is the advantage of doing things
this way? Was my google search too lax so that I missed a FAQ
somewhere?
Kind regards,