Should this bunch of typedefs be private or public?
c++, class, graph, typedef
Solution
1. Access control in C++ is applied purely to names. There's a note and example in ISO/IEC 14882:2011 11 [class.access]/4 that makes it clear that this is the intention.
`[...] [ 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 ]
2. it is ok, as you can make some type meaningful and easily understandable.
Problem
I'm writing a class that represents a graph, so I've wrote the following header ``` 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); }; ``` I have some questions about the above code: - Should I declare the bunch of typedefs public or private? - Is it a normal practice, when one typedefs one type to different synonyms (like typedef int VertexNum; typedef int Weight;)?