I have a class tree_nodeand tree.
template<typename T>
class tree_node
{
public:
tree_node(const std::string& key_, const T& value_)
: key(key_), value(value_)
{
}
private:
T value;
std::string key;
};
template<typename T>
class tree
{
public:
tree() : root(new tree_node<T>("", ???)) { }
private:
tree_node<T>* root;
};
tree_nodeexpects an instance Tat creation. How to transfer it to the field ???? I can say T(), but it will only work if it Thas a constructor without parameters. I cannot have a constructor without parameters for tree_node, since it will not compile if it Tdoes not have a constructor without parameters.
I am looking for a development method tree_nodethat can contain all types correctly, including pointer types.
Edit
, boost::optional. T value boost::optional<T> value. . tree_node, key. node. ?
..