I wrote an iterator class inside my HashSet class.
However, a few constructors of the iterator class will only be used inside the HashSet class.
I thought it was a good idea to hide them from the user by making them private. Is there a way to make inner class private methods accessible to outer class?
If not, is there another way to make those constructors only accessible from the inside of HashSet class?
Edit:
I know how to access outer class private members from inner class, but I am asking how to access inner class private members from outer class, so the question is not a duplicate.
This is my source code:
template <typename val_type,
typename prehash = std::hash<val_type> >
class HashSet {
...
template<typename val_type>
class forward_iterator :
public std::iterator<std::forward_iterator_tag, SList<val_type> > {
public: // I want to keep those 3 constructors
// accessible to anyone
forward_iterator() :
ptr(nullptr),
parent(nullptr),
pos(-1)
{}
forward_iterator(const forward_iterator* rhs) :
ptr(rhs->ptr),
parent(rhs->parent),
ptr_it(rhs->ptr_it),
pos(rhs->pos)
{}
forward_iterator(const forward_iterator& rhs) :
ptr(rhs.ptr),
parent(rhs.parent),
ptr_it(rhs.ptr_it),
pos(rhs.pos)
{}
private: // I want to hide the below constructors
//from anyone not in
//HashSet class
forward_iterator(pointer p, list_iterator liter, HashSet* prnt,
long long int pos_) :
ptr(p),
ptr_it(liter),
parent(prnt),
pos(pos_)
{}
forward_iterator(reference p, list_iterator liter, HashSet* prnt,
long long int pos_) :
ptr(p),
ptr_it(liter),
parent(prnt),
pos(pos_)
{}
...
};
...
};