比如这种情况
class Node {
public:
int index;
std::vector<Edge> outs;
};
class Edge {
public:
double weight;
Node vertex;
};
ringa_lee2017-04-17 13:15:20
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.
ringa_lee2017-04-17 13:15:20
Calling classes to each other feels like there is something wrong with this design