Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Class x needs defining before class y, circular dependecy

Class x needs defining before class y, circular dependecy

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studiodesign
9 Posts 4 Posters 0 Views 1 Watching
  • 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.
  • Y Offline
    Y Offline
    Ylis
    wrote on last edited by
    #1

    Okay, I'l try my best to describe the problem at hand. This is what the relations looks like:

    CQuad :
    implements CNodeInterface

    CNodeInterface :
    knows of CScene

    CScene:
    knows of CQuad
    knows of CNodeInterface

    I have some nasty circular dependency here, I know, but I can't seem to design it away. Anyway, the problem is that CNodeInterface needs to be defined before CQuad gets defined, however no matter how I tinker I can't seem to get this to happen. With forward declarations I still get errors in CQuad that CNodeInterface is undefined. Part of the problem is that I don't even know what decides which gets defined first when there's circular dependency. I'm using Visual Studio 2005. Any help appreciated.

    W Z L 3 Replies Last reply
    0
    • Y Ylis

      Okay, I'l try my best to describe the problem at hand. This is what the relations looks like:

      CQuad :
      implements CNodeInterface

      CNodeInterface :
      knows of CScene

      CScene:
      knows of CQuad
      knows of CNodeInterface

      I have some nasty circular dependency here, I know, but I can't seem to design it away. Anyway, the problem is that CNodeInterface needs to be defined before CQuad gets defined, however no matter how I tinker I can't seem to get this to happen. With forward declarations I still get errors in CQuad that CNodeInterface is undefined. Part of the problem is that I don't even know what decides which gets defined first when there's circular dependency. I'm using Visual Studio 2005. Any help appreciated.

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      A forward declaration isn't going to work if you are calling functions from within that class. Did you try adding an extern forward declaration?

      Y 1 Reply Last reply
      0
      • Y Ylis

        Okay, I'l try my best to describe the problem at hand. This is what the relations looks like:

        CQuad :
        implements CNodeInterface

        CNodeInterface :
        knows of CScene

        CScene:
        knows of CQuad
        knows of CNodeInterface

        I have some nasty circular dependency here, I know, but I can't seem to design it away. Anyway, the problem is that CNodeInterface needs to be defined before CQuad gets defined, however no matter how I tinker I can't seem to get this to happen. With forward declarations I still get errors in CQuad that CNodeInterface is undefined. Part of the problem is that I don't even know what decides which gets defined first when there's circular dependency. I'm using Visual Studio 2005. Any help appreciated.

        Z Offline
        Z Offline
        Zac Howland
        wrote on last edited by
        #3

        If you post some of the relevant code, someone may be able to offer you an alternative design. Circular dependencies should be avoided, and doing so will also avoid your compilation problem.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        Y 1 Reply Last reply
        0
        • W Waldermort

          A forward declaration isn't going to work if you are calling functions from within that class. Did you try adding an extern forward declaration?

          Y Offline
          Y Offline
          Ylis
          wrote on last edited by
          #4

          Yupp, and I'm still geting the same compilation error :(

          1 Reply Last reply
          0
          • Z Zac Howland

            If you post some of the relevant code, someone may be able to offer you an alternative design. Circular dependencies should be avoided, and doing so will also avoid your compilation problem.

            If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

            Y Offline
            Y Offline
            Ylis
            wrote on last edited by
            #5

            CScene is a scene graph. CNodeInterface is an abstract class that defines the interface for nodes in the scene graph. CQuad in turn is a type of node that lies at the top of the scene graph and creates a quad tree for sub nodes that later on implements CNodeInterface lies in.

            1 Reply Last reply
            0
            • Y Ylis

              Okay, I'l try my best to describe the problem at hand. This is what the relations looks like:

              CQuad :
              implements CNodeInterface

              CNodeInterface :
              knows of CScene

              CScene:
              knows of CQuad
              knows of CNodeInterface

              I have some nasty circular dependency here, I know, but I can't seem to design it away. Anyway, the problem is that CNodeInterface needs to be defined before CQuad gets defined, however no matter how I tinker I can't seem to get this to happen. With forward declarations I still get errors in CQuad that CNodeInterface is undefined. Part of the problem is that I don't even know what decides which gets defined first when there's circular dependency. I'm using Visual Studio 2005. Any help appreciated.

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              You need some design changes. We don't have enough information yet to help much with that.

              led mike

              Y 1 Reply Last reply
              0
              • L led mike

                You need some design changes. We don't have enough information yet to help much with that.

                led mike

                Y Offline
                Y Offline
                Ylis
                wrote on last edited by
                #7

                Okay, I'l try my best to describe the problem more precisely. Before I go into further details, this is an implementation of a scene graph holding a quad tree, something used in graphics programming in order to arrange elements in space to avoid sending unnecesary data to the graphics card. First of all there's CScene, which represents the scene graph. CScene holds a tree of nodes and functionality for inserting in that tree and manipulating it. Since this tree can hold a lot of diffrent types of nodes, I need to just define a very loose interface for the minimum required functionality of a node that needs to be implemented ( such as Update, Render, AddChild etc ). That interface is called CNodeInterface. When CScene is created it will create the upper elements of the tree with CQuads, this is to create the quad tree. This is how it could look for example:

                ROOT
                |
                |---Quad 1
                | |
                | |---Quad 1.1
                | |
                | |---Player
                | |
                | |---Sword
                |
                |---Quad 2
                |---Quad 3
                |---Quad 4
                |

                In order to save space I've left out nodes under Quad 2, 3 and 4 as well as 3 sub quads under Quad 1. Player and Sword implements CNodeInterface. Thankful for any help :)

                W L 2 Replies Last reply
                0
                • Y Ylis

                  Okay, I'l try my best to describe the problem more precisely. Before I go into further details, this is an implementation of a scene graph holding a quad tree, something used in graphics programming in order to arrange elements in space to avoid sending unnecesary data to the graphics card. First of all there's CScene, which represents the scene graph. CScene holds a tree of nodes and functionality for inserting in that tree and manipulating it. Since this tree can hold a lot of diffrent types of nodes, I need to just define a very loose interface for the minimum required functionality of a node that needs to be implemented ( such as Update, Render, AddChild etc ). That interface is called CNodeInterface. When CScene is created it will create the upper elements of the tree with CQuads, this is to create the quad tree. This is how it could look for example:

                  ROOT
                  |
                  |---Quad 1
                  | |
                  | |---Quad 1.1
                  | |
                  | |---Player
                  | |
                  | |---Sword
                  |
                  |---Quad 2
                  |---Quad 3
                  |---Quad 4
                  |

                  In order to save space I've left out nodes under Quad 2, 3 and 4 as well as 3 sub quads under Quad 1. Player and Sword implements CNodeInterface. Thankful for any help :)

                  W Offline
                  W Offline
                  Waldermort
                  wrote on last edited by
                  #8

                  From your desrciption it sounds more like you need a polymorphic style layout rather than cyclic. Try deriving your classes from a common base class, then pass a pointer to the base class around rather than the derived classes. Again, without seeing exactly what you are trying to do it's kinda hard to give you advice.

                  1 Reply Last reply
                  0
                  • Y Ylis

                    Okay, I'l try my best to describe the problem more precisely. Before I go into further details, this is an implementation of a scene graph holding a quad tree, something used in graphics programming in order to arrange elements in space to avoid sending unnecesary data to the graphics card. First of all there's CScene, which represents the scene graph. CScene holds a tree of nodes and functionality for inserting in that tree and manipulating it. Since this tree can hold a lot of diffrent types of nodes, I need to just define a very loose interface for the minimum required functionality of a node that needs to be implemented ( such as Update, Render, AddChild etc ). That interface is called CNodeInterface. When CScene is created it will create the upper elements of the tree with CQuads, this is to create the quad tree. This is how it could look for example:

                    ROOT
                    |
                    |---Quad 1
                    | |
                    | |---Quad 1.1
                    | |
                    | |---Player
                    | |
                    | |---Sword
                    |
                    |---Quad 2
                    |---Quad 3
                    |---Quad 4
                    |

                    In order to save space I've left out nodes under Quad 2, 3 and 4 as well as 3 sub quads under Quad 1. Player and Sword implements CNodeInterface. Thankful for any help :)

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    Ylis wrote:

                    First of all there's CScene, which represents the scene graph

                    That does not provide enough context to understand the purpose/roll/responsibility of CScene

                    Ylis wrote:

                    I need to just define a very loose interface for the minimum required functionality of a node that needs to be implemented ( such as Update, Render, AddChild etc )

                    It does not seem that AddChild belongs in the same type as Update and Render. Your QuadNode should likely be a template container then you might have an interface containing the Update and Render methods and then you would implement QuadNode root node (your tree) with the interface as the template parameter. interface ISceneEntitiy void Render( canvas or device context etc) void Update(....) tempate class QuadNode { // implements AddChild, Remove, and accessors, iterators for traversing etc. } then somewhere (we don't have enough information to know where) QuadNode _rootNode; then you Player and Sword implement the ISceneEntity interface Then you likely need some Creational Pattern to generate (populate) the tree. Then if the tree is mutable you likely need some Manager to contain the logic of change to the tree. There might be much more than this but again we don't have enough information to go on.

                    led mike

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups