I am doing a project using generic templates in C++ in modular programming (we don't use OOP concepts)
We are having an issue understanding how to refer in an auxiliary function to a single variable in the template, which is a struct itself, without referring to the whole struct.
To put an example, because it sounds weird, we have:
template<typename T>
struct tree {
friend void addElement<T> (tree<T>& c, const T& e);
struct Node {
T element; // template element
Nodo* left;
Nodo* right;
};
Node* root;
int size;
}
template<typename T>
void friend void addElement<T> (tree<T>& c, const T& e);
insert(c.root, e);
c.size++;
}
// auxiliary function
template<typename T>
void insert(tree<T>root node, const T& e) {
// how to refer to taking a Node* as an argument? we want
// to modify the node structure of the tree in a recursive way,
// so we will need to pass Node->left or Node->right as arguments
// code
}
We have tried multiple ways of doing this, none worked so far. How could this be done?
Thanks!
Aucun commentaire:
Enregistrer un commentaire