Thread: Circular Dependency A Dead End?

  1. #1
    Registered User Waleed Mujeeb's Avatar
    Join Date
    Jan 2012
    Posts
    22

    Circular Dependency A Dead End?

    //parent.h File
    Code:
    #include "child.h"
    class child;
    class parent
    { 
      child *pc; 
      child c;   //Gives ERROR
    };
    
    //child.h File
    class parent;
    class child
    {
      parent *pp;
      parent p;  //Gives ERROR
    };
    I am currently having some serious circular dependency issues with my design. Is there a way to declare an object(not a pointer) in this case. Does circular dependency occur because of a serious design flaw?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Suppose it were possible. Then a parent has a child subobject. A child has a parent subobject. That parent subobject has a child subobject, which has a parent subobject, which has a child subobject... sorry, the sum of all the memories of all the computers in the world is far too small to contain even a single parent object.

    So, what are you really trying to model?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Waleed Mujeeb's Avatar
    Join Date
    Jan 2012
    Posts
    22
    I get it now ,an infinite cycle. I am trying a make a 2d shooter for my project. I started abusing OOP. Problem solved i dont need an input class. Sorry for really coming up with such a dumb question, never mind.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VS9 Breakpoint a dependency?
    By Glorfindel in forum C++ Programming
    Replies: 2
    Last Post: 04-07-2009, 10:47 PM
  2. Dependency Properties
    By DavidP in forum C# Programming
    Replies: 0
    Last Post: 05-23-2008, 09:21 AM
  3. Circular main <- main.o dependency dropped.
    By Queatrix in forum C++ Programming
    Replies: 4
    Last Post: 10-21-2005, 02:32 PM
  4. Replies: 3
    Last Post: 08-31-2005, 12:41 PM
  5. Circular dependency / Compile Error
    By jester in forum C++ Programming
    Replies: 4
    Last Post: 05-23-2003, 11:17 PM