Results 1 to 7 of 7

Thread: Circular reference ... Unable to write forwarding

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Circular reference ... Unable to write forwarding

    I have a class.h with only structs definition
    I have a methods.h with a class WW with some functions written as templates.

    Ok, I have to declare into class.h instances to WW.
    But, I have to declare #include class.h into WW so the templates can use the structures declared in class.h.

    All can be solved if I could write forwarding at class.h, but I have not class.cpp.

    Here is my code :

    class.h
    Qt Code:
    1. struct Tpun {
    2. int one_data;
    3. WW myww1;
    4. };
    To copy to clipboard, switch view to plain text mode 
    methods.h

    Qt Code:
    1. #include "class.h"
    2.  
    3. class WW {
    4. public:
    5. WW();
    6. ~WW();
    7.  
    8.  
    9. template <class TT_stream>
    10. void put(TT_stream &value);
    11.  
    12. };
    13.  
    14. template <class TT_stream>
    15. void WW::put (TT_stream &value) { }
    To copy to clipboard, switch view to plain text mode 


    Any help ?
    How can I tell to class.h that uses WW ? I cant write #include "methods.h" becasue then I have circular reference ...
    Have I to write class.cpp and move my structs from .h to there ?
    Last edited by tonnot; 27th June 2011 at 10:16.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Circular reference ... Unable to write forwarding

    In the code you posted, class WW does not use struct Tpun, post the class / struct which are in circular reference..

    Any way, you can change struct Tpun as

    Qt Code:
    1. class WW;
    2.  
    3. struct Tpun {
    4. int one_data;
    5. WW * myww1;
    6. };
    To copy to clipboard, switch view to plain text mode 

    All can solved if I can write forwarding at class.h, but I have not class.cpp.
    can explain this again, its not clear

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Circular reference ... Unable to write forwarding

    Sorry, class.h has more than T_pun struct, in example, Tpoint.
    Both class and WW are using by a third class.
    In it, I create a Tpun element and a Tpoint element.

    Later I want to do Tpun.myww1.put(Tpoint);
    As you can see the put method is a template. It needs to know the structures to use. These structures are stored at class.h.

    So I have circular reference classh #include "methods.h" and methods.h has #include "class.h"
    To can write forwarding I need to write the #include at the cpp file. So I think the solution can be to move my structs from class.h to class.cpp ?
    Thanks

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Circular reference ... Unable to write forwarding

    You did not get my question, I will try again...

    Quote Originally Posted by Santosh Reddy
    In the code you posted, class WW does not use struct Tpun, post the class / struct which are in circular reference..
    - In class.h
    Tpun is dependent on WW, so include method.h

    - In method.h
    WW is not dependent on Tpun, so don't include class.h


    Also needless to mention, I hope you are using inclusion guard macros

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Circular reference ... Unable to write forwarding

    Yes ... of course I have guard macros.
    I can't put all the code for method.h, but believe me , it needs to knows some structs of class.h.
    So, as I have to declare the template functions on my class.h ( The templates implementatin cannot be written at cpp , isn't ) I have two options :
    Re-write my template functions to explicit types.
    Re-study my classes to write a third ...

    Thanks for your time.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Circular reference ... Unable to write forwarding

    I would recommend to move all templates to a top level file, (I hope your template implementation does not depend on class.h)

  7. The following user says thank you to Santosh Reddy for this useful post:

    tonnot (27th June 2011)

  8. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Circular reference ... Unable to write forwarding

    Thanks again

Similar Threads

  1. signal forwarding
    By FelixB in forum Qt Programming
    Replies: 3
    Last Post: 27th January 2011, 08:55
  2. OpenGL shaders and x11 forwarding
    By Wali in forum Qt Programming
    Replies: 0
    Last Post: 2nd November 2010, 21:38
  3. Unable to write to file QFile
    By cuter in forum Qt Programming
    Replies: 4
    Last Post: 15th July 2009, 11:19
  4. Forwarding mouse events to another widget.
    By yogeshm02 in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2006, 13:25
  5. Is there a circular reference here?
    By rh in forum General Programming
    Replies: 3
    Last Post: 22nd January 2006, 21:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.