我可以让c ++代码结构相互看到吗?

时间:2016-06-05 16:23:56

标签: c++ structure

我不擅长英语..抱歉

例如,

struct structure1
{
   structure2 st;
}

struct structure2
{
   structure1 st;
}

它有不完整的类型错误

如何使用此代码?

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

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

这是我的真实代码

它是图算法的一部分

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;
    }
};

谢谢!

1 个答案:

答案 0 :(得分:2)

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

您可以使用引用或指针。请参阅here如何执行此操作:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Being Java Guys | Registration Form</title>
</head>
<body>
<center>
<br><br><br><br><br><br>
<div style="color: teal;font-size: 30px">Being Java Guys | Registration Form</div>
<br><br>
<c:url var="userRegistration" value="saveUser.html"/>
<form:form id="registerForm" modelAttribute="user" method="post" action="${userRegistration}">
<table width="400px" height="150px">
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input  path="firstName"/></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input  path="lastName"/></td>
</tr>
<tr>
<td><form:label path="gender">Gender</form:label></td>
<td><form:radiobuttons path="gender" items="${model.gender}"/></td>
</tr>
<tr>
<td><form:label path="city">City</form:label></td>
<td><form:select path="city" items="${model.city}"></form:select></td>
</tr>
<tr><td></td><td>
<input type="submit" value="Register" />
</td></tr>
</table>
</form:form>
<br>
<a href="userList.html" >Click Here to see User List</a>
</center>
</body>
</html>

Live Demo