Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Does it problem to have circularity? Does it means circularity?
Forum Updated to NodeBB v4.3 + New Features

Does it problem to have circularity? Does it means circularity?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 222 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RuWex
    wrote on last edited by
    #1

    if I have :

    class A{
    B* b;
    }
    
    class B{
    A* a;
    }
    

    Is it problem?? How can I solve it if I really need this pointers?

    Does this Idea will solve it?
    When creating A in the constructor, I create B and send it to the constructor itself?
    thank:)

    JonBJ jsulmJ 2 Replies Last reply
    0
    • R RuWex

      if I have :

      class A{
      B* b;
      }
      
      class B{
      A* a;
      }
      

      Is it problem?? How can I solve it if I really need this pointers?

      Does this Idea will solve it?
      When creating A in the constructor, I create B and send it to the constructor itself?
      thank:)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @RuWex
      What is the "problem" here? It should work OK, because you are using pointers, e.g.

      A *a = new A;
      B *b = new B;
      a->b = b;
      b->a = a;
      

      or in, say, the constructor of A:

      this->b = new B;
      this->b->a = this;
      
      1 Reply Last reply
      1
      • R RuWex

        if I have :

        class A{
        B* b;
        }
        
        class B{
        A* a;
        }
        

        Is it problem?? How can I solve it if I really need this pointers?

        Does this Idea will solve it?
        When creating A in the constructor, I create B and send it to the constructor itself?
        thank:)

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #3

        @RuWex said in Does it problem to have circularity? Does it means circularity?:

        Is it problem??

        What problem are you talking about?
        If you have the problem with header files reversely including each other then the solution is simple: forward declarations without including herder files inside other header files (include those in cpp files):

        // Header for A
        class B; // Forward declaration for class B
        class A{
        B* b;
        }
        
        // Header for B
        class A; // Forward declaration for class A
        class B{
        A* a;
        }
        

        Keep in mind: forward declarations only works if you use pointers.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        4

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved