I’ve got a template class like so:
template<class T>
class List
{
private:
struct node
{
T value;
node *next, *prev;
};
}
When creating instances of this List class with T = myClass* I have no problems, since value will be a pointer, but if it’s an object, creating a node instance results in “No appropiate default constructor available” error, if this class has no default constructor.
I could solve this by changing T value to T *value, but I need to have copies of these values inside of the list, so that if they’re removed outside of the list, they remain valid in here.
What would be the right way of aproaching this?
You could provide a constructor for
nodethat requires an instance ofTfrom which a copy can be constructed:This would change the requirement on
Tfrom default constructible to copy constructible. Any type in your list would require a copy constructor.