I'm writing a simple data structure for a tree.
I have these classes:
//declaration of tree_pos_vector
template<class T>
class tree_pos_vector;
template<class T>
class node{
private:
int pos;
int num_children;
/*other member and function
...
*/
public:
/*other function
....
*/
template<class W> friend class tree_pos_vector;
friend std::ostream& operator<<(std::ostream &os,tree_pos_vector<T>& _tree);
}
template<class T>
class tree_pos_vector{
private:
std::vector<node<T>*> vec_node;
/*other member and function
...
*/
public:
/*other function
...
*/
friend std::ostream& operator<<(std::ostream &os,tree_pos_vector<T>& _tree){
for(auto &n: _tree.vec_node){
for(int i=0;i < n->num_children; i++){
os<< "( "<<*n<<","<< vec_node[n->pos*degree+i] << ")\n";
}
}
}
}
The problem is that the members n->num_children
and n->pos
remains private and I cannot access them from this function.
Where is the problem?
There is a way to access to private member of node from operator<<
function?