Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7946559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:11:19+00:00 2026-06-04T01:11:19+00:00

I had faced a circular dependency in my program and solved it with using

  • 0

I had faced a circular dependency in my program and solved it with using pointers and forward declarations. I had made a file dn.hpp for this purpose. Everything was OK until I moved to shared pointers instead of generic. I created typedefs for shared pointers in dn.hpp. Everything works with generic pointers (commented out), bun not with shared.

It returns an error:
field ‘parentGraph’ has incomplete type node.h line 21

(I am using mingw with boost 1.47)

Please help me to resolve this issue.

Here is simplified version of my code:

dn.hpp

// forward declarations
#include <map>
#include <list>
#include <boost/shared_ptr.hpp>

class graph;
typedef boost::weak_ptr<graph> graph_wp;
typedef boost::shared_ptr<graph> graph_sp;
//typedef graph* graph_wp;
//typedef graph* graph_sp;

class node;
typedef boost::weak_ptr<node> node_wp;
typedef boost::shared_ptr<node> node_sp;
//typedef node* node_wp;
//typedef node* node_sp;
typedef std::list<node_sp> nodes_t;

class edge;
typedef boost::weak_ptr<edge> edge_wp;
typedef boost::shared_ptr<edge> edge_sp;
//typedef edge* edge_wp;
//typedef edge* edge_sp;
typedef std::list<edge_sp> edges_t;
typedef std::list<edge_wp> edgeList_t;

graph.h

#ifndef GRAPH_H_
#define GRAPH_H_

#include "node.h"
#include "edge.h"

#include "dn.hpp"

class graph
{
public:
    node* createNode();
protected:
    nodes_t nodes;
    edges_t edges;
};
#endif /*GRAPH_H_ */

node.h

#ifndef NODE_H_
#define NODE_H_

#include "graph.h"
#include "edge.h"

#include "dn.hpp"

class node
{
public:
    node();
    node(graph_wp n);
    node(const graph_wp& net);
    virtual ~node();

    edge_wp createChild();
protected:
    graph_wp parentGraph;
    edgeList_t edges;
};
#endif /* NODE_H_ */

edge.h

#ifndef EDGE_H_
#define EDGE_H_

#include "node.h"

#include "dn.hpp"

class edge
{
public:
    edge(node_wp src,node_wp tgt);
    virtual ~edge();
private:
    node_sp source;
    node_sp target;
};
#endif /* EDGE_H_ */

main.cpp

#include "graph.h"
int main() {
    graph n;
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:11:21+00:00Added an answer on June 4, 2026 at 1:11 am

    When I compile your code with VisualStudio I get

    error C2079: 'node::parentGraph' uses undefined class 'boost::weak_ptr<Y>'
    with
    [
        Y=graph
    ]
    

    Adding

    #include <boost/weak_ptr.hpp>
    

    fixes this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I defined this program in terms of a C++ program because I faced this
Recently I had faced compiling errors in a c++ code I wrote so I've
i am facing a new situation. I know someone definitely had faced these type
Had a page that was working fine. Only change I made was to add
Had this working; at one stage. The problem is the following text is now
I had this problem before and can't for life of me remember how to
We faced an issue with file Merge at TFS2010. Until now, we merged files
Faced with choosing a Dependency Injection Framework in a historically MS shop working with
I have faced this problem when working with ORACLE 10g. I read the answers
I had telephone interview question yesterday. The interviewer asked me if I had faced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.