c++ - 两个类如何能够相互使用?
大家讲道理
大家讲道理 2017-04-17 13:13:20
0
2
497

比如这种情况

class Node {
public:
    int index;
    std::vector<Edge> outs;
};

class Edge {
public:
    double weight;
    Node vertex;
};
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
左手右手慢动作

Let me make a statement first.

#include<vector>

class Edge;

class Node {
public:
    int index;
    std::vector<Edge> outs;
};

class Edge {
public:
    double weight;
    Node vertex;
};

Strictly speaking, Node should use Edge pointers or references, or explicitly support incomplete type containers. However, generally vectors are implemented based on pointers, so there is no problem.

左手右手慢动作

Calling classes to each other feels like there is something wrong with this design

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template