vor*_*192 5 c++ typedef class graph
我正在写一个代表图形的类,所以我写了下面的标题
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);
};
Run Code Online (Sandbox Code Playgroud)
我对上面的代码有一些疑问:
1. C++中的访问控制纯粹适用于名称.ISO/IEC 14882:2011 11 [class.access]/4中有一个注释和示例,表明这是意图.
[...] [ Note: Because access control applies to names, if access control is applied to a typedef name, only the accessibility of the typedef name itself is considered. The accessibility of the entity referred to by the typedef is not considered. For example,
class A {
class B { };
public:
typedef B BB;
};
void f() {
A::BB x; // OK, typedef name A::BB is public
A::B y; // access error, A::B is private
}
—end note ]
Run Code Online (Sandbox Code Playgroud)
2.没关系,因为你可以使某些类型有意义且容易理解.