【发布时间】:2014-05-23 08:17:42
【问题描述】:
我正在写一个代表图表的类,所以我写了以下标题
class Graph {
public:
Graph();
Graph(int N);
void addVertex();
void addEdge(VertexNum v1, VertexNum v2, Weight w);
std::pair<PathLength, Path> shortestPath
(const VerticesGroup& V1, const VerticesGroup& V2);
private:
typedef int VertexNum;
typedef int Weight;
typedef std::pair<VertexNum, Weight> Edge;
typedef std::vector<Edge> Path;
typedef size_t PathLength;
typedef std::vector<VertexNum> VerticesGroup;
std::vector<std::list<Edge> > adjList;
bool incorrectVertexNumber(VertexNum v);
};
我对上面的代码有一些疑问:
- 我应该将这组 typedef 声明为 public 还是 private?
- 当一个 typedef 将一种类型定义为不同的同义词(如 typedef int VertexNum; typedef int Weight;)时,这是一种正常的做法吗?
【问题讨论】: