我可以让c ++代码结构看到对方吗? [英] Can I make c++ code structure see each other?

查看:156
本文介绍了我可以让c ++代码结构看到对方吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不擅长英语。对不起。

Im not good at English.. sorry

例如

struct structure1
{
   structure2 st;
}

struct structure2
{
   structure1 st;
}

它有不完整的类型错误

我如何使用这个代码?

它在java中工作良好,但在c ++我认为是自上而下的过程..

It is work well in java but in c++ I think because top down process..

我不知道它有解决方案好工作

I wonder It has solution good work

这是我真正的代码

它是图算法的一部分

struct Edge
{
    Node destination;

    int capacity;

    int cost;

    Edge dual;

    Edge(Node n, int c, int s)
    {
        capacity = c;

        cost = s;

        destination = n;

        dual.cost = -9999;
    }

};

struct Node
{
    int cost;

    vector<Edge> edges;

    Edge from;

    string name;

    bool onq;

    Node()
    {
        from.capacity = -9999;
    }

    void clear()
    {
        cost = 0;
        edges.clear();
        from.capacity = -9999;
    }
};

谢谢!!

推荐答案

不,你不能这样做。这将是一个无尽的递归。

No you can't do this. It would be an endless recursion.

您可以使用引用或指针。请参见此处如何操作:

You could use a reference or a pointer though. See here how to do this:

struct structure2; // <<< forward declaration 
struct structure1
{
   structure2* st; // <<< use a pointer (or reference) 
   structure1(structure2* s2) : st(s2) {} // <<< initialize the pointer
};

struct structure2
{
   structure1 st;
   structure2() : st(this) {} // <<< pass the pointer
};

现场演示

这篇关于我可以让c ++代码结构看到对方吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆