Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QApplication>
- #include <QDebug>
- class InnerClass;
- struct OuterClass
- {
- const QList<InnerClass*>& list() const
- {
- return _list;
- }
- QList<InnerClass*> _list;
- };
- struct InnerClass
- {
- OuterClass const*const parent;
- InnerClass(OuterClass *parent)
- : parent { parent }
- {
- }
- int index() const
- {
- return parent->list().indexOf(this);
- }
- };
- void test() {
- OuterClass outer;
- outer._list.append(new InnerClass(&outer));
- outer._list.append(new InnerClass(&outer));
- outer._list.append(new InnerClass(&outer));
- qDebug() << outer.list().last()->index();
- }
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- test();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement