Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: [C++] When two classes call on each other?

Started 3 months, 2 weeks ago by dr.silly
my program roughly looks like this: Code: class Item { Q_OBJECT public: List parent; }; class List { Q_OBJECT public: QList<Item> list; }; The problem is no matter which class is compiled first it will require the other class which wasn't compiled. What's the way around this?
Site: Ubuntu Forums - Online Community  Ubuntu Forums - Online Community - site profile
Forum: Programming Talk  Programming Talk - forum profile
Total authors: 2 authors
Total thread posts: 2 posts
Thread activity: no new posts during last week
Domain info for: ubuntuforums.org

Other posts in this thread:

dribeas replied 3 months, 2 weeks ago
In the general case, if you have two classes that depend on each other and one dependency is only on references or pointers, you can forward declare one of them before declaring the other, and define the methods after both are declared: Code: struct X; struct Y { Y( X & other ); // arguments (passed by pointer/reference/value are allowed) X f(); // return values are ...

 

Top contributing authors

Name
Posts
dr.silly
1
user's latest post:
[C++] When two classes call on...
Published (2009-09-15 17:03:34)
my program roughly looks like this: Code: class Item { Q_OBJECT public: List parent; }; class List { Q_OBJECT public: QList&lt;Item&gt; list; }; The problem is no matter which class is compiled first it will require the other class which wasn't compiled. What's the way around this?
dribeas
1
user's latest post:
[C++] When two classes call on...
Published (2009-09-15 17:11:34)
In the general case, if you have two classes that depend on each other and one dependency is only on references or pointers, you can forward declare one of them before declaring the other, and define the methods after both are declared: Code: struct X; struct Y { Y( X &amp; other ); // arguments (passed by pointer/reference/value are allowed) X f(); // return values are allowed X* xp; // pointers are allowed X&amp; xr; // so are...

Related threads on "Ubuntu Forums - Online Community":

Related threads on other sites:

Thread profile page for "[C++] When two classes call on each other?" on http://ubuntuforums.org. This report page is a snippet summary view from a single thread "[C++] When two classes call on each other?", located on the Message Board at http://ubuntuforums.org. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity